Commit 4b27c9d7 authored by Russ Cox's avatar Russ Cox

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/4643Reviewed-by: 's avatarAustin Clements <austin@google.com>
parent fa7efa2c
......@@ -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
......
......@@ -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)
{
......
......@@ -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;
......
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