]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: revert package typecheck part of CL 422914
authorMatthew Dempsky <mdempsky@google.com>
Fri, 2 Dec 2022 01:32:47 +0000 (17:32 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Wed, 25 Jan 2023 18:32:34 +0000 (18:32 +0000)
This code path is unreachable anyway, and it adds new uses of
Type.Pkg, which shouldn't be used anymore.

Mark Type.Pkg as deprecated while here.

Updates #57410.

Change-Id: I1eec1c8ed99207d58d0ba0c44822bbad29dc64f3
Reviewed-on: https://go-review.googlesource.com/c/go/+/458575
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
src/cmd/compile/internal/typecheck/expr.go
src/cmd/compile/internal/typecheck/stmt.go
src/cmd/compile/internal/typecheck/subr.go
src/cmd/compile/internal/types/type.go

index 0cd69abb80f86a94a6eeadb8c9dea3de23fad60c..96f368363a2c65ddb1a1f45a53060608f8eb3af7 100644 (file)
@@ -516,18 +516,6 @@ func tcDot(n *ir.SelectorExpr, top int) ir.Node {
        return n
 }
 
-func wrongTypeFor(haveSym *types.Sym, haveType *types.Type, wantSym *types.Sym, wantType *types.Type) string {
-       haveT := fmt.Sprintf("%S", haveType)
-       wantT := fmt.Sprintf("%S", wantType)
-       if haveT == wantT {
-               // Add packages instead of reporting "got Foo but wanted Foo", see #54258.
-               haveT = haveType.Pkg().Path + "." + haveT
-               wantT = wantType.Pkg().Path + "." + wantT
-       }
-       return fmt.Sprintf("(wrong type for %v method)\n"+
-               "\t\thave %v%s\n\t\twant %v%s", wantSym, haveSym, haveT, wantSym, wantT)
-}
-
 // tcDotType typechecks an ODOTTYPE node.
 func tcDotType(n *ir.TypeAssertExpr) ir.Node {
        n.X = Expr(n.X)
@@ -551,8 +539,8 @@ func tcDotType(n *ir.TypeAssertExpr) ir.Node {
                var ptr int
                if !implements(n.Type(), t, &missing, &have, &ptr) {
                        if have != nil && have.Sym == missing.Sym {
-                               base.Errorf("impossible type assertion:\n\t%v does not implement %v %s", n.Type(), t,
-                                       wrongTypeFor(have.Sym, have.Type, missing.Sym, missing.Type))
+                               base.Errorf("impossible type assertion:\n\t%v does not implement %v (wrong type for %v method)\n"+
+                                       "\t\thave %v%S\n\t\twant %v%S", n.Type(), t, missing.Sym, have.Sym, have.Type, missing.Sym, missing.Type)
                        } else if ptr != 0 {
                                base.Errorf("impossible type assertion:\n\t%v does not implement %v (%v method has pointer receiver)", n.Type(), t, missing.Sym)
                        } else if have != nil {
index 9d57edb39fc36a435d4af74af323921986f43ef4..5eeab4115e3a61c97ae6e12183fba650ab0c2f06 100644 (file)
@@ -604,8 +604,8 @@ func tcSwitchType(n *ir.SwitchStmt) {
                        }
                        if !n1.Type().IsInterface() && !implements(n1.Type(), t, &missing, &have, &ptr) {
                                if have != nil {
-                                       base.ErrorfAt(ncase.Pos(), "impossible type switch case: %L cannot have dynamic type %v %s", guard.X, n1.Type(),
-                                               wrongTypeFor(have.Sym, have.Type, missing.Sym, missing.Type))
+                                       base.ErrorfAt(ncase.Pos(), "impossible type switch case: %L cannot have dynamic type %v"+
+                                               " (wrong type for %v method)\n\thave %v%S\n\twant %v%S", guard.X, n1.Type(), missing.Sym, have.Sym, have.Type, missing.Sym, missing.Type)
                                } else if ptr != 0 {
                                        base.ErrorfAt(ncase.Pos(), "impossible type switch case: %L cannot have dynamic type %v"+
                                                " (%v method has pointer receiver)", guard.X, n1.Type(), missing.Sym)
index 29d992f32431f275f0aedc3de6d891d60393b86a..bfe27cb60d054c738a15c18029ba6abadff9ba0b 100644 (file)
@@ -397,7 +397,8 @@ func Assignop1(src, dst *types.Type) (ir.Op, string) {
                } else if have != nil && have.Sym == missing.Sym && have.Nointerface() {
                        why = fmt.Sprintf(":\n\t%v does not implement %v (%v method is marked 'nointerface')", src, dst, missing.Sym)
                } else if have != nil && have.Sym == missing.Sym {
-                       why = fmt.Sprintf(":\n\t%v does not implement %v %s", src, dst, wrongTypeFor(have.Sym, have.Type, missing.Sym, missing.Type))
+                       why = fmt.Sprintf(":\n\t%v does not implement %v (wrong type for %v method)\n"+
+                               "\t\thave %v%S\n\t\twant %v%S", src, dst, missing.Sym, have.Sym, have.Type, missing.Sym, missing.Type)
                } else if ptr != 0 {
                        why = fmt.Sprintf(":\n\t%v does not implement %v (%v method has pointer receiver)", src, dst, missing.Sym)
                } else if have != nil {
index d426c2cb8e1f1261e48c79b301b51405edd2cc9e..c717d6d86dad572d326033f8dc693a570299119f 100644 (file)
@@ -319,6 +319,9 @@ var NoPkg *Pkg = nil
 // (i.e., types with named elements). This information isn't used by
 // cmd/compile itself, but we need to track it because it's exposed by
 // the go/types API.
+//
+// Deprecated: Pkg exists only for iexport, which will go away after
+// Go 1.20. It should not be used by other code.
 func (t *Type) Pkg() *Pkg {
        switch t.kind {
        case TFUNC: