mirror of
https://github.com/golang/go
synced 2024-11-17 05:24:53 -07:00
cmd/compile/internal/types2: add Interface.IsMethodSet, remove Interface.IsContraint
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>
This commit is contained in:
parent
3a555977fc
commit
8cf0a087c0
@ -1687,7 +1687,7 @@ func (w *writer) pkgDecl(decl syntax.Decl) {
|
|||||||
name := w.p.info.Defs[decl.Name].(*types2.TypeName)
|
name := w.p.info.Defs[decl.Name].(*types2.TypeName)
|
||||||
// Skip type declarations for interfaces that are only usable as
|
// Skip type declarations for interfaces that are only usable as
|
||||||
// type parameter bounds.
|
// 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
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ func (check *Checker) callExpr(x *operand, call *syntax.CallExpr) exprKind {
|
|||||||
check.expr(x, call.ArgList[0])
|
check.expr(x, call.ArgList[0])
|
||||||
if x.mode != invalid {
|
if x.mode != invalid {
|
||||||
if t := asInterface(T); t != nil {
|
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)
|
check.errorf(call, "cannot use interface %s in conversion (contains type list or is comparable)", T)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -534,7 +534,7 @@ func (check *Checker) isImportedConstraint(typ Type) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
u, _ := named.under().(*Interface)
|
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) {
|
func (check *Checker) typeDecl(obj *TypeName, tdecl *syntax.TypeDecl, def *Named) {
|
||||||
|
@ -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.
|
// IsComparable reports whether each type in interface t's type set is comparable.
|
||||||
func (t *Interface) IsComparable() bool { return t.typeSet().IsComparable() }
|
func (t *Interface) IsComparable() bool { return t.typeSet().IsComparable() }
|
||||||
|
|
||||||
// IsConstraint reports whether interface t is not just a method set.
|
// IsMethodSet reports whether the interface t is fully described by its method set.
|
||||||
func (t *Interface) IsConstraint() bool { return t.typeSet().IsConstraint() }
|
func (t *Interface) IsMethodSet() bool { return t.typeSet().IsMethodSet() }
|
||||||
|
|
||||||
func (t *Interface) Underlying() Type { return t }
|
func (t *Interface) Underlying() Type { return t }
|
||||||
func (t *Interface) String() string { return TypeString(t, nil) }
|
func (t *Interface) String() string { return TypeString(t, nil) }
|
||||||
|
@ -30,8 +30,8 @@ func (s *_TypeSet) IsAll() bool {
|
|||||||
return !s.comparable && len(s.methods) == 0 && s.terms.isAll()
|
return !s.comparable && len(s.methods) == 0 && s.terms.isAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsConstraint reports whether type set s is not just a set of methods.
|
// IsMethodSet reports whether the interface t is fully described by its method set.
|
||||||
func (s *_TypeSet) IsConstraint() bool { return s.comparable || !s.terms.isAll() }
|
func (s *_TypeSet) IsMethodSet() bool { return !s.comparable && s.terms.isAll() }
|
||||||
|
|
||||||
// IsComparable reports whether each type in the set is comparable.
|
// IsComparable reports whether each type in the set is comparable.
|
||||||
func (s *_TypeSet) IsComparable() bool {
|
func (s *_TypeSet) IsComparable() bool {
|
||||||
|
@ -143,7 +143,7 @@ func (check *Checker) varType(e syntax.Expr) Type {
|
|||||||
if t := asInterface(typ); t != nil {
|
if t := asInterface(typ); t != nil {
|
||||||
pos := syntax.StartPos(e)
|
pos := syntax.StartPos(e)
|
||||||
tset := computeInterfaceTypeSet(check, pos, t) // TODO(gri) is this the correct position?
|
tset := computeInterfaceTypeSet(check, pos, t) // TODO(gri) is this the correct position?
|
||||||
if tset.IsConstraint() {
|
if !tset.IsMethodSet() {
|
||||||
if tset.comparable {
|
if tset.comparable {
|
||||||
check.softErrorf(pos, "interface is (or embeds) comparable")
|
check.softErrorf(pos, "interface is (or embeds) comparable")
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user