mirror of
https://github.com/golang/go
synced 2024-11-19 02:14:43 -07:00
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
This commit is contained in:
parent
410927d1ad
commit
2a7019894a
@ -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;
|
||||
|
@ -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:
|
||||
|
@ -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?
|
||||
|
Loading…
Reference in New Issue
Block a user