Skip to content

Commit 91a935e

Browse files
committed
Revert "go/types: make Interface.Complete a no-op"
This reverts commit fda8ee8. Reason for revert: Interface.Complete is still necessary for safe concurrency. For #47726 Change-Id: I8b924ca5f4af8c7d7e2b5a27bb03a5a5ed9b1d22 Reviewed-on: https://go-review.googlesource.com/c/go/+/342710 Trust: Robert Findley <[email protected]> Run-TryBot: Robert Findley <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Robert Griesemer <[email protected]>
1 parent a8d39f1 commit 91a935e

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

src/go/internal/gcimporter/iimport.go

+4
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,10 @@ func iImportData(fset *token.FileSet, imports map[string]*types.Package, dataRea
174174
p.doDecl(localpkg, name)
175175
}
176176

177+
for _, typ := range p.interfaceList {
178+
typ.Complete()
179+
}
180+
177181
// record all referenced packages as imports
178182
list := append(([]*types.Package)(nil), pkgList[1:]...)
179183
sort.Sort(byPath(list))

src/go/types/interface.go

+14-4
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,22 @@ func (t *Interface) IsComparable() bool { return t.typeSet().IsComparable() }
104104
// IsConstraint reports whether interface t is not just a method set.
105105
func (t *Interface) IsConstraint() bool { return !t.typeSet().IsMethodSet() }
106106

107-
// Complete just returns its receiver. There's no other effect.
107+
// Complete computes the interface's type set. It must be called by users of
108+
// NewInterfaceType and NewInterface after the interface's embedded types are
109+
// fully defined and before using the interface type in any way other than to
110+
// form other types. The interface must not contain duplicate methods or a
111+
// panic occurs. Complete returns the receiver.
108112
//
109-
// Deprecated: Interfaces are now completed on demand; this function is only
110-
// here for backward-compatibility. It does not have to be called explicitly
111-
// anymore.
113+
// Deprecated: Type sets are now computed lazily, on demand; this function
114+
// is only here for backward-compatibility. It does not have to
115+
// be called explicitly anymore.
112116
func (t *Interface) Complete() *Interface {
117+
// Some tests are still depending on the state change
118+
// (string representation of an Interface not containing an
119+
// /* incomplete */ marker) caused by the explicit Complete
120+
// call, so we compute the type set eagerly here.
121+
t.complete = true
122+
t.typeSet()
113123
return t
114124
}
115125

src/go/types/issues_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -405,9 +405,8 @@ func TestIssue28282(t *testing.T) {
405405
// create type interface { error }
406406
et := Universe.Lookup("error").Type()
407407
it := NewInterfaceType(nil, []Type{et})
408+
it.Complete()
408409
// verify that after completing the interface, the embedded method remains unchanged
409-
// (interfaces are "completed" lazily now, so the completion happens implicitly when
410-
// accessing Method(0))
411410
want := et.Underlying().(*Interface).Method(0)
412411
got := it.Method(0)
413412
if got != want {

0 commit comments

Comments
 (0)