]> Cypherpunks repositories - gostls13.git/commitdiff
gc: better error for method non-call
authorRuss Cox <rsc@golang.org>
Thu, 7 Oct 2010 08:42:44 +0000 (04:42 -0400)
committerRuss Cox <rsc@golang.org>
Thu, 7 Oct 2010 08:42:44 +0000 (04:42 -0400)
was
x.go:7: must call (&b).*Buffer·Write

now
x.go:7: method b.Write is not an expression, must be called

Fixes #1171.

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

src/cmd/gc/go.h
src/cmd/gc/print.c
src/cmd/gc/typecheck.c

index 490710b7e00ff6a978b8e4ee0239cb9addbcc22c..ec1ada74ed94da8988fae3c2bfc2c92783cee1d9 100644 (file)
@@ -210,8 +210,9 @@ struct      Node
        uchar   dodata;         // compile literal assignment as data statement
        uchar   used;
        uchar   isddd;
-       uchar   pun;            // dont registerize variable ONAME
+       uchar   pun;            // don't registerize variable ONAME
        uchar   readonly;
+       uchar   implicit;       // don't show in printout
 
        // most nodes
        Node*   left;
index ca013fabb3fddfad607beda0dd7e0481ad069632..32e8b7de55251d6ea1eee712c65adc4d215b580c 100644 (file)
@@ -23,12 +23,18 @@ void
 exprfmt(Fmt *f, Node *n, int prec)
 {
        int nprec;
+       char *p;
 
        nprec = 0;
        if(n == nil) {
                fmtprint(f, "<nil>");
                return;
        }
+       
+       if(n->implicit) {
+               exprfmt(f, n->left, prec);
+               return;
+       }
 
        switch(n->op) {
        case ONAME:
@@ -298,8 +304,15 @@ exprfmt(Fmt *f, Node *n, int prec)
                exprfmt(f, n->left, 7);
                if(n->right == N || n->right->sym == S)
                        fmtprint(f, ".<nil>");
-               else
-                       fmtprint(f, ".%s", n->right->sym->name);
+               else {
+                       // skip leading type· in method name
+                       p = utfrrune(n->right->sym->name, 0xb7);
+                       if(p)
+                               p+=2;
+                       else
+                               p = n->right->sym->name;
+                       fmtprint(f, ".%s", p);
+               }
                break;
 
        case ODOTTYPE:
index f139ee8210233dd2f375dbd9c87383c20108b421..28382f1fd219adf264749d50345f9f9cbe81f22a 100644 (file)
@@ -1254,7 +1254,7 @@ ret:
                goto error;
        }
        if((ok & Ecall) && !(top & Ecall)) {
-               yyerror("must call %#N", n);
+               yyerror("method %#N is not an expression, must be called", n);
                goto error;
        }
        // TODO(rsc): simplify
@@ -1483,9 +1483,11 @@ lookdot(Node *n, Type *t, int dostrcmp)
                                checklvalue(n->left, "call pointer method on");
                                addrescapes(n->left);
                                n->left = nod(OADDR, n->left, N);
+                               n->left->implicit = 1;
                                typecheck(&n->left, Etype|Erv);
                        } else if(tt->etype == tptr && eqtype(tt->type, rcvr)) {
                                n->left = nod(OIND, n->left, N);
+                               n->left->implicit = 1;
                                typecheck(&n->left, Etype|Erv);
                        } else {
                                // method is attached to wrong type?