Commit 2a701989 authored by Russ Cox's avatar Russ Cox

gc: better error for method non-call

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
parent 410927d1
...@@ -210,8 +210,9 @@ struct Node ...@@ -210,8 +210,9 @@ struct Node
uchar dodata; // compile literal assignment as data statement uchar dodata; // compile literal assignment as data statement
uchar used; uchar used;
uchar isddd; uchar isddd;
uchar pun; // dont registerize variable ONAME uchar pun; // don't registerize variable ONAME
uchar readonly; uchar readonly;
uchar implicit; // don't show in printout
// most nodes // most nodes
Node* left; Node* left;
......
...@@ -23,6 +23,7 @@ void ...@@ -23,6 +23,7 @@ void
exprfmt(Fmt *f, Node *n, int prec) exprfmt(Fmt *f, Node *n, int prec)
{ {
int nprec; int nprec;
char *p;
nprec = 0; nprec = 0;
if(n == nil) { if(n == nil) {
...@@ -30,6 +31,11 @@ exprfmt(Fmt *f, Node *n, int prec) ...@@ -30,6 +31,11 @@ exprfmt(Fmt *f, Node *n, int prec)
return; return;
} }
if(n->implicit) {
exprfmt(f, n->left, prec);
return;
}
switch(n->op) { switch(n->op) {
case ONAME: case ONAME:
case ONONAME: case ONONAME:
...@@ -298,8 +304,15 @@ exprfmt(Fmt *f, Node *n, int prec) ...@@ -298,8 +304,15 @@ exprfmt(Fmt *f, Node *n, int prec)
exprfmt(f, n->left, 7); exprfmt(f, n->left, 7);
if(n->right == N || n->right->sym == S) if(n->right == N || n->right->sym == S)
fmtprint(f, ".<nil>"); fmtprint(f, ".<nil>");
else {
// skip leading type· in method name
p = utfrrune(n->right->sym->name, 0xb7);
if(p)
p+=2;
else else
fmtprint(f, ".%s", n->right->sym->name); p = n->right->sym->name;
fmtprint(f, ".%s", p);
}
break; break;
case ODOTTYPE: case ODOTTYPE:
......
...@@ -1254,7 +1254,7 @@ ret: ...@@ -1254,7 +1254,7 @@ ret:
goto error; goto error;
} }
if((ok & Ecall) && !(top & Ecall)) { if((ok & Ecall) && !(top & Ecall)) {
yyerror("must call %#N", n); yyerror("method %#N is not an expression, must be called", n);
goto error; goto error;
} }
// TODO(rsc): simplify // TODO(rsc): simplify
...@@ -1483,9 +1483,11 @@ lookdot(Node *n, Type *t, int dostrcmp) ...@@ -1483,9 +1483,11 @@ lookdot(Node *n, Type *t, int dostrcmp)
checklvalue(n->left, "call pointer method on"); checklvalue(n->left, "call pointer method on");
addrescapes(n->left); addrescapes(n->left);
n->left = nod(OADDR, n->left, N); n->left = nod(OADDR, n->left, N);
n->left->implicit = 1;
typecheck(&n->left, Etype|Erv); typecheck(&n->left, Etype|Erv);
} else if(tt->etype == tptr && eqtype(tt->type, rcvr)) { } else if(tt->etype == tptr && eqtype(tt->type, rcvr)) {
n->left = nod(OIND, n->left, N); n->left = nod(OIND, n->left, N);
n->left->implicit = 1;
typecheck(&n->left, Etype|Erv); typecheck(&n->left, Etype|Erv);
} else { } else {
// method is attached to wrong type? // method is attached to wrong type?
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment