aboutsummaryrefslogtreecommitdiff
path: root/src/go
diff options
context:
space:
mode:
authorRobert Findley <rfindley@google.com>2021-08-16 23:50:47 +0000
committerRobert Findley <rfindley@google.com>2021-08-17 02:49:38 +0000
commit91a935ea0f525c04016dd37c45143af942ffd3fc (patch)
treed29455de6711c8e042dc8e99ac89a2a4d6a8d78c /src/go
parenta8d39f151d10209bca94c7533786dcc9c55c9517 (diff)
downloadgo-91a935ea0f525c04016dd37c45143af942ffd3fc.tar.gz
go-91a935ea0f525c04016dd37c45143af942ffd3fc.zip
Revert "go/types: make Interface.Complete a no-op"
This reverts commit fda8ee8b077dd8a5819cac7c52c3af1499a0674e. 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 <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
Diffstat (limited to 'src/go')
-rw-r--r--src/go/internal/gcimporter/iimport.go4
-rw-r--r--src/go/types/interface.go18
-rw-r--r--src/go/types/issues_test.go3
3 files changed, 19 insertions, 6 deletions
diff --git a/src/go/internal/gcimporter/iimport.go b/src/go/internal/gcimporter/iimport.go
index 5f05e8c0ad..dbc9b3a83e 100644
--- a/src/go/internal/gcimporter/iimport.go
+++ b/src/go/internal/gcimporter/iimport.go
@@ -174,6 +174,10 @@ func iImportData(fset *token.FileSet, imports map[string]*types.Package, dataRea
p.doDecl(localpkg, name)
}
+ for _, typ := range p.interfaceList {
+ typ.Complete()
+ }
+
// record all referenced packages as imports
list := append(([]*types.Package)(nil), pkgList[1:]...)
sort.Sort(byPath(list))
diff --git a/src/go/types/interface.go b/src/go/types/interface.go
index f4d560cb3e..510c123e97 100644
--- a/src/go/types/interface.go
+++ b/src/go/types/interface.go
@@ -104,12 +104,22 @@ func (t *Interface) IsComparable() bool { return t.typeSet().IsComparable() }
// IsConstraint reports whether interface t is not just a method set.
func (t *Interface) IsConstraint() bool { return !t.typeSet().IsMethodSet() }
-// Complete just returns its receiver. There's no other effect.
+// Complete computes the interface's type set. It must be called by users of
+// NewInterfaceType and NewInterface after the interface's embedded types are
+// fully defined and before using the interface type in any way other than to
+// form other types. The interface must not contain duplicate methods or a
+// panic occurs. Complete returns the receiver.
//
-// Deprecated: Interfaces are now completed on demand; this function is only
-// here for backward-compatibility. It does not have to be called explicitly
-// anymore.
+// Deprecated: Type sets are now computed lazily, on demand; this function
+// is only here for backward-compatibility. It does not have to
+// be called explicitly anymore.
func (t *Interface) Complete() *Interface {
+ // Some tests are still depending on the state change
+ // (string representation of an Interface not containing an
+ // /* incomplete */ marker) caused by the explicit Complete
+ // call, so we compute the type set eagerly here.
+ t.complete = true
+ t.typeSet()
return t
}
diff --git a/src/go/types/issues_test.go b/src/go/types/issues_test.go
index 618db13fb9..51995af30a 100644
--- a/src/go/types/issues_test.go
+++ b/src/go/types/issues_test.go
@@ -405,9 +405,8 @@ func TestIssue28282(t *testing.T) {
// create type interface { error }
et := Universe.Lookup("error").Type()
it := NewInterfaceType(nil, []Type{et})
+ it.Complete()
// verify that after completing the interface, the embedded method remains unchanged
- // (interfaces are "completed" lazily now, so the completion happens implicitly when
- // accessing Method(0))
want := et.Underlying().(*Interface).Method(0)
got := it.Method(0)
if got != want {