1
0
mirror of https://github.com/golang/go synced 2024-11-20 10:04:45 -07:00

gc: interface error message fixes

Fixes #1526.

R=ken2
CC=golang-dev
https://golang.org/cl/4190051
This commit is contained in:
Russ Cox 2011-02-17 16:33:26 -05:00
parent dd7403b1b8
commit 6e03ed32c7
2 changed files with 8 additions and 4 deletions

View File

@ -1909,8 +1909,12 @@ assignop(Type *src, Type *dst, char **why)
return 0; return 0;
} }
if(src->etype == TINTER && dst->etype != TBLANK) { if(src->etype == TINTER && dst->etype != TBLANK) {
if(why != nil) if(why != nil) {
*why = ": need type assertion"; if(isptrto(dst, TINTER))
*why = smprint(":\n\t%T is interface, not pointer to interface", src);
else
*why = ": need type assertion";
}
return 0; return 0;
} }

View File

@ -1613,7 +1613,7 @@ typecheckaste(int op, Node *call, int isddd, Type *tstruct, NodeList *nl, char *
exportassignok(tn->type, desc); exportassignok(tn->type, desc);
if(assignop(tn->type, tl->type->type, &why) == 0) { if(assignop(tn->type, tl->type->type, &why) == 0) {
if(call != N) if(call != N)
yyerror("cannot use %T as type %T in argument to %#N%s", tn->type, tl->type->type, desc, call, why); yyerror("cannot use %T as type %T in argument to %#N%s", tn->type, tl->type->type, call, why);
else else
yyerror("cannot use %T as type %T in %s%s", tn->type, tl->type->type, desc, why); yyerror("cannot use %T as type %T in %s%s", tn->type, tl->type->type, desc, why);
} }
@ -1625,7 +1625,7 @@ typecheckaste(int op, Node *call, int isddd, Type *tstruct, NodeList *nl, char *
exportassignok(tn->type, desc); exportassignok(tn->type, desc);
if(assignop(tn->type, tl->type, &why) == 0) { if(assignop(tn->type, tl->type, &why) == 0) {
if(call != N) if(call != N)
yyerror("cannot use %T as type %T in argument to %#N%s", tn->type, tl->type, desc, call, why); yyerror("cannot use %T as type %T in argument to %#N%s", tn->type, tl->type, call, why);
else else
yyerror("cannot use %T as type %T in %s%s", tn->type, tl->type, desc, why); yyerror("cannot use %T as type %T in %s%s", tn->type, tl->type, desc, why);
} }