]> Cypherpunks repositories - gostls13.git/commitdiff
gc: interface error message fixes
authorRuss Cox <rsc@golang.org>
Thu, 17 Feb 2011 21:33:26 +0000 (16:33 -0500)
committerRuss Cox <rsc@golang.org>
Thu, 17 Feb 2011 21:33:26 +0000 (16:33 -0500)
Fixes #1526.

R=ken2
CC=golang-dev
https://golang.org/cl/4190051

src/cmd/gc/subr.c
src/cmd/gc/typecheck.c

index 0755ca3cd5481b5b5d1ddc83d4db8f43a060ba9d..49df50319f968d121fa38dcc86208ea30ca8b17e 100644 (file)
@@ -1909,8 +1909,12 @@ assignop(Type *src, Type *dst, char **why)
                return 0;
        }
        if(src->etype == TINTER && dst->etype != TBLANK) {
-               if(why != nil)
-                       *why = ": need type assertion";
+               if(why != nil) {
+                       if(isptrto(dst, TINTER))
+                               *why = smprint(":\n\t%T is interface, not pointer to interface", src);
+                       else    
+                               *why = ": need type assertion";
+               }
                return 0;
        }
 
index 5edca964aa1014cd827f135d085c1d8a209e94af..731e5a49ed6411fb42c35c2dd2beb8b6376b0c73 100644 (file)
@@ -1613,7 +1613,7 @@ typecheckaste(int op, Node *call, int isddd, Type *tstruct, NodeList *nl, char *
                                        exportassignok(tn->type, desc);
                                        if(assignop(tn->type, tl->type->type, &why) == 0) {
                                                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
                                                        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);
                        if(assignop(tn->type, tl->type, &why) == 0) {
                                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
                                        yyerror("cannot use %T as type %T in %s%s", tn->type, tl->type, desc, why);
                        }