1
0
mirror of https://github.com/golang/go synced 2024-11-18 09:54:57 -07:00

cmd/gc: add .y to error about missing x in x.y

If the Go source says x.y, and x is undefined, today we get

	undefined: x

Change to:

	undefined: x in x.y

Change-Id: I8ea95503bd469ea933c6bcbd675b7122a5d454f3
Reviewed-on: https://go-review.googlesource.com/4643
Reviewed-by: Austin Clements <austin@google.com>
This commit is contained in:
Russ Cox 2015-02-05 12:31:13 -05:00
parent fa7efa2cb0
commit 4b27c9d72e
3 changed files with 20 additions and 2 deletions

View File

@ -1448,6 +1448,7 @@ void warn(char *fmt, ...);
void warnl(int line, char *fmt, ...);
void yyerror(char *fmt, ...);
void yyerrorl(int line, char *fmt, ...);
void adderrorname(Node*);
/*
* swt.c

View File

@ -38,6 +38,19 @@ parserline(void)
return lineno;
}
void
adderrorname(Node *n)
{
char *old;
if(n->op != ODOT)
return;
old = smprint("%L: undefined: %N\n", n->lineno, n->left);
if(nerr > 0 && err[nerr-1].lineno == n->lineno && strcmp(err[nerr-1].msg, old) == 0)
err[nerr-1].msg = smprint("%L: undefined: %N in %N\n", n->lineno, n->left, n);
free(old);
}
static void
adderr(int line, char *fmt, va_list arg)
{

View File

@ -786,12 +786,14 @@ reswitch:
case ODOT:
typecheck(&n->left, Erv|Etype);
defaultlit(&n->left, T);
if((t = n->left->type) == T)
goto error;
if(n->right->op != ONAME) {
yyerror("rhs of . must be a name"); // impossible
goto error;
}
if((t = n->left->type) == T) {
adderrorname(n);
goto error;
}
r = n->right;
if(n->left->op == OTYPE) {
@ -3303,6 +3305,8 @@ typecheckdef(Node *n)
n->diag = 1;
if(n->lineno != 0)
lineno = n->lineno;
// Note: adderrorname looks for this string and
// adds context about the outer expression
yyerror("undefined: %S", n->sym);
}
return n;