check.invalidOp(x, _InvalidAssert, "%s is not an interface", x)
goto Error
}
- check.ordinaryType(x, xtyp)
// x.(type) expressions are handled explicitly in type switches
if e.Type == nil {
// Don't use invalidAST because this can occur in the AST produced by
}
// varType type-checks the type expression e and returns its type, or Typ[Invalid].
-// The type must not be an (uninstantiated) generic type and it must be ordinary
-// (see ordinaryType).
+// The type must not be an (uninstantiated) generic type and it must not be a
+// constraint interface.
func (check *Checker) varType(e ast.Expr) Type {
typ := check.definedType(e, nil)
- check.ordinaryType(e, typ)
- return typ
-}
-
-// ordinaryType reports an error if typ is an interface type containing
-// type lists or is (or embeds) the predeclared type comparable.
-func (check *Checker) ordinaryType(pos positioner, typ Type) {
// We don't want to call under() (via asInterface) or complete interfaces while we
// are in the middle of type-checking parameter declarations that might belong to
// interface methods. Delay this check to the end of type-checking.
check.later(func() {
if t := asInterface(typ); t != nil {
- tset := computeInterfaceTypeSet(check, pos.Pos(), t) // TODO(gri) is this the correct position?
+ tset := computeInterfaceTypeSet(check, e.Pos(), t) // TODO(gri) is this the correct position?
if tset.IsConstraint() {
if tset.comparable {
- check.softErrorf(pos, _Todo, "interface is (or embeds) comparable")
+ check.softErrorf(e, _Todo, "interface is (or embeds) comparable")
} else {
- check.softErrorf(pos, _Todo, "interface contains type constraints")
+ check.softErrorf(e, _Todo, "interface contains type constraints")
}
}
}
})
+
+ return typ
}
// anyType type-checks the type expression e and returns its type, or Typ[Invalid].