Skip to content

Commit a896219

Browse files
committed
cmd/compile: revert package typecheck part of CL 422914
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 <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Matthew Dempsky <[email protected]> Reviewed-by: Cherry Mui <[email protected]>
1 parent 77cd3a4 commit a896219

File tree

4 files changed

+9
-17
lines changed

4 files changed

+9
-17
lines changed

src/cmd/compile/internal/typecheck/expr.go

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -516,18 +516,6 @@ func tcDot(n *ir.SelectorExpr, top int) ir.Node {
516516
return n
517517
}
518518

519-
func wrongTypeFor(haveSym *types.Sym, haveType *types.Type, wantSym *types.Sym, wantType *types.Type) string {
520-
haveT := fmt.Sprintf("%S", haveType)
521-
wantT := fmt.Sprintf("%S", wantType)
522-
if haveT == wantT {
523-
// Add packages instead of reporting "got Foo but wanted Foo", see #54258.
524-
haveT = haveType.Pkg().Path + "." + haveT
525-
wantT = wantType.Pkg().Path + "." + wantT
526-
}
527-
return fmt.Sprintf("(wrong type for %v method)\n"+
528-
"\t\thave %v%s\n\t\twant %v%s", wantSym, haveSym, haveT, wantSym, wantT)
529-
}
530-
531519
// tcDotType typechecks an ODOTTYPE node.
532520
func tcDotType(n *ir.TypeAssertExpr) ir.Node {
533521
n.X = Expr(n.X)
@@ -551,8 +539,8 @@ func tcDotType(n *ir.TypeAssertExpr) ir.Node {
551539
var ptr int
552540
if !implements(n.Type(), t, &missing, &have, &ptr) {
553541
if have != nil && have.Sym == missing.Sym {
554-
base.Errorf("impossible type assertion:\n\t%v does not implement %v %s", n.Type(), t,
555-
wrongTypeFor(have.Sym, have.Type, missing.Sym, missing.Type))
542+
base.Errorf("impossible type assertion:\n\t%v does not implement %v (wrong type for %v method)\n"+
543+
"\t\thave %v%S\n\t\twant %v%S", n.Type(), t, missing.Sym, have.Sym, have.Type, missing.Sym, missing.Type)
556544
} else if ptr != 0 {
557545
base.Errorf("impossible type assertion:\n\t%v does not implement %v (%v method has pointer receiver)", n.Type(), t, missing.Sym)
558546
} else if have != nil {

src/cmd/compile/internal/typecheck/stmt.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -604,8 +604,8 @@ func tcSwitchType(n *ir.SwitchStmt) {
604604
}
605605
if !n1.Type().IsInterface() && !implements(n1.Type(), t, &missing, &have, &ptr) {
606606
if have != nil {
607-
base.ErrorfAt(ncase.Pos(), "impossible type switch case: %L cannot have dynamic type %v %s", guard.X, n1.Type(),
608-
wrongTypeFor(have.Sym, have.Type, missing.Sym, missing.Type))
607+
base.ErrorfAt(ncase.Pos(), "impossible type switch case: %L cannot have dynamic type %v"+
608+
" (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)
609609
} else if ptr != 0 {
610610
base.ErrorfAt(ncase.Pos(), "impossible type switch case: %L cannot have dynamic type %v"+
611611
" (%v method has pointer receiver)", guard.X, n1.Type(), missing.Sym)

src/cmd/compile/internal/typecheck/subr.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,8 @@ func Assignop1(src, dst *types.Type) (ir.Op, string) {
397397
} else if have != nil && have.Sym == missing.Sym && have.Nointerface() {
398398
why = fmt.Sprintf(":\n\t%v does not implement %v (%v method is marked 'nointerface')", src, dst, missing.Sym)
399399
} else if have != nil && have.Sym == missing.Sym {
400-
why = fmt.Sprintf(":\n\t%v does not implement %v %s", src, dst, wrongTypeFor(have.Sym, have.Type, missing.Sym, missing.Type))
400+
why = fmt.Sprintf(":\n\t%v does not implement %v (wrong type for %v method)\n"+
401+
"\t\thave %v%S\n\t\twant %v%S", src, dst, missing.Sym, have.Sym, have.Type, missing.Sym, missing.Type)
401402
} else if ptr != 0 {
402403
why = fmt.Sprintf(":\n\t%v does not implement %v (%v method has pointer receiver)", src, dst, missing.Sym)
403404
} else if have != nil {

src/cmd/compile/internal/types/type.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,9 @@ var NoPkg *Pkg = nil
319319
// (i.e., types with named elements). This information isn't used by
320320
// cmd/compile itself, but we need to track it because it's exposed by
321321
// the go/types API.
322+
//
323+
// Deprecated: Pkg exists only for iexport, which will go away after
324+
// Go 1.20. It should not be used by other code.
322325
func (t *Type) Pkg() *Pkg {
323326
switch t.kind {
324327
case TFUNC:

0 commit comments

Comments
 (0)