]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/compile/internal/types2: add Interface.IsMethodSet, remove Interface.IsContraint
authorRobert Griesemer <gri@golang.org>
Tue, 28 Sep 2021 16:56:38 +0000 (09:56 -0700)
committerRobert Griesemer <gri@golang.org>
Tue, 28 Sep 2021 17:50:53 +0000 (17:50 +0000)
This is a port of CL 352616 from go/types to types2. It also removes
Interface.IsConstraint and adjusts all uses to use IsMethodSet. The
dual changes are made to the (unexported) type set implementation.

Change-Id: I292b741d1f7cdbaefb483eed75faf7b85a8d2792
Reviewed-on: https://go-review.googlesource.com/c/go/+/352872
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
src/cmd/compile/internal/noder/writer.go
src/cmd/compile/internal/types2/call.go
src/cmd/compile/internal/types2/decl.go
src/cmd/compile/internal/types2/interface.go
src/cmd/compile/internal/types2/typeset.go
src/cmd/compile/internal/types2/typexpr.go

index 47de9920339c2d36b256eff9dae15436ead6cc17..dde42c85d6ef2618f726e3850ee08230f6968416 100644 (file)
@@ -1687,7 +1687,7 @@ func (w *writer) pkgDecl(decl syntax.Decl) {
                name := w.p.info.Defs[decl.Name].(*types2.TypeName)
                // Skip type declarations for interfaces that are only usable as
                // type parameter bounds.
-               if iface, ok := name.Type().Underlying().(*types2.Interface); ok && iface.IsConstraint() {
+               if iface, ok := name.Type().Underlying().(*types2.Interface); ok && !iface.IsMethodSet() {
                        break
                }
 
index 5cf292ce8ad0cedadcf352663f9cbfc4096ee376..118e76fdcf41663a455a7868c3e4af3d5dd57e82 100644 (file)
@@ -103,7 +103,7 @@ func (check *Checker) callExpr(x *operand, call *syntax.CallExpr) exprKind {
                        check.expr(x, call.ArgList[0])
                        if x.mode != invalid {
                                if t := asInterface(T); t != nil {
-                                       if t.IsConstraint() {
+                                       if !t.IsMethodSet() {
                                                check.errorf(call, "cannot use interface %s in conversion (contains type list or is comparable)", T)
                                                break
                                        }
index ab2e3b875f0a9fe3f0d4d188a855c7f39249dcd1..326763d9b79350ec1c48e250ba6618ff1de216e0 100644 (file)
@@ -534,7 +534,7 @@ func (check *Checker) isImportedConstraint(typ Type) bool {
                return false
        }
        u, _ := named.under().(*Interface)
-       return u != nil && u.IsConstraint()
+       return u != nil && !u.IsMethodSet()
 }
 
 func (check *Checker) typeDecl(obj *TypeName, tdecl *syntax.TypeDecl, def *Named) {
index 340df51524b8584e4a2645437e8652ac78b9579a..8a6bc75c43f5d9b07a31f4b06b01f6d8de3f395c 100644 (file)
@@ -98,8 +98,8 @@ func (t *Interface) Empty() bool { return t.typeSet().IsAll() }
 // IsComparable reports whether each type in interface t's type set is comparable.
 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().IsConstraint() }
+// IsMethodSet reports whether the interface t is fully described by its method set.
+func (t *Interface) IsMethodSet() bool { return t.typeSet().IsMethodSet() }
 
 func (t *Interface) Underlying() Type { return t }
 func (t *Interface) String() string   { return TypeString(t, nil) }
index c56aa56e2ea09eadcd61ff0e15c594bb1e379f31..37030b2ca16df0fd6971a4e720ef4a7de7da579b 100644 (file)
@@ -30,8 +30,8 @@ func (s *_TypeSet) IsAll() bool {
        return !s.comparable && len(s.methods) == 0 && s.terms.isAll()
 }
 
-// IsConstraint reports whether type set s is not just a set of methods.
-func (s *_TypeSet) IsConstraint() bool { return s.comparable || !s.terms.isAll() }
+// IsMethodSet reports whether the interface t is fully described by its method set.
+func (s *_TypeSet) IsMethodSet() bool { return !s.comparable && s.terms.isAll() }
 
 // IsComparable reports whether each type in the set is comparable.
 func (s *_TypeSet) IsComparable() bool {
index 3bfce2ebf25115849a13cd71c06fc0e55dc90c53..62cfda825ff00d00c986fcc4f7a7989bf96d3d99 100644 (file)
@@ -143,7 +143,7 @@ func (check *Checker) varType(e syntax.Expr) Type {
                if t := asInterface(typ); t != nil {
                        pos := syntax.StartPos(e)
                        tset := computeInterfaceTypeSet(check, pos, t) // TODO(gri) is this the correct position?
-                       if tset.IsConstraint() {
+                       if !tset.IsMethodSet() {
                                if tset.comparable {
                                        check.softErrorf(pos, "interface is (or embeds) comparable")
                                } else {