]> Cypherpunks repositories - gostls13.git/commitdiff
go/types: remove superfluous ordinaryType calls
authorRobert Findley <rfindley@google.com>
Tue, 31 Aug 2021 22:26:16 +0000 (18:26 -0400)
committerRobert Findley <rfindley@google.com>
Wed, 1 Sep 2021 00:37:23 +0000 (00:37 +0000)
This is a port of CL 346291 to go/types.

Change-Id: I8f864aca5cdb4037bc27a81cde1597430b9a48db
Reviewed-on: https://go-review.googlesource.com/c/go/+/346559
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>

src/go/types/expr.go
src/go/types/stmt.go
src/go/types/testdata/fixedbugs/issue42758.go2
src/go/types/typexpr.go

index 2a204cf5f688a4f54521090f4f2f9812db2385af..e5741565624b8274cdd02ab5c50695ea7f637303 100644 (file)
@@ -1386,7 +1386,6 @@ func (check *Checker) exprInternal(x *operand, e ast.Expr, hint Type) exprKind {
                        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
index e74862afef067eba0a3871e08bcfb7a903a4fd41..e5830bfdd4169740621bd1030b5ce6de968c13da 100644 (file)
@@ -696,7 +696,6 @@ func (check *Checker) stmt(ctxt stmtContext, s ast.Stmt) {
                        check.errorf(&x, _InvalidTypeSwitch, "%s is not an interface", &x)
                        return
                }
-               check.ordinaryType(&x, xtyp)
 
                check.multipleDefaults(s.Body.List)
 
index bf0031f5d244305720afb8c8d2f2710c5b8bbaf9..dd66e9648b56326f364b4ade15b459a506a5bb9d 100644 (file)
@@ -28,6 +28,6 @@ func _[T constraint](x interface{}){
 }
 
 func _(x constraint /* ERROR contains type constraints */ ) {
-       switch x /* ERROR contains type constraints */ .(type) {
+       switch x.(type) { // no need to report another error
        }
 }
index a126241afa8cf9d3cffce3935371f3b0b5f7f32e..533f976f1d8bdf6d53f7f1230df712dc89bd8e6a 100644 (file)
@@ -132,32 +132,27 @@ func (check *Checker) typ(e ast.Expr) Type {
 }
 
 // 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].