Skip to content

Commit 38fd519

Browse files
committed
cmd/compile: Revise error msg in type assertion ptr/non-ptr condition
Revise the error message under the condition that type assertion has mismatching pointer/non-pointer type. close #43673
1 parent 928bda4 commit 38fd519

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,13 @@ func typecheck1(n *Node, top int) (res *Node) {
999999
yyerror("impossible type assertion:\n\t%v does not implement %v (missing %v method)\n"+
10001000
"\t\thave %v%0S\n\t\twant %v%0S", n.Type, t, missing.Sym, have.Sym, have.Type, missing.Sym, missing.Type)
10011001
} else {
1002-
yyerror("impossible type assertion:\n\t%v does not implement %v (missing %v method)", n.Type, t, missing.Sym)
1002+
var _missing, _have *types.Field
1003+
var _ptr int
1004+
if implements(derefall(n.Type), t, &_missing, &_have, &_ptr) {
1005+
yyerror("impossible type assertion:\n\t instead of type %v need to type assert to %v", n.Type, derefall(n.Type))
1006+
} else {
1007+
yyerror("impossible type assertion:\n\t%v does not implement %v (missing %v method)", n.Type, t, missing.Sym)
1008+
}
10031009
}
10041010
n.Type = nil
10051011
return n

0 commit comments

Comments
 (0)