Commit 70a27347 authored by Russ Cox's avatar Russ Cox

better error; clean up lineno in a few places

wreck.mtv=; cat x.go
package main
var x = string.Split()
wreck.mtv=; 6g x.go
x.go:2: type string used as expression
x.go:2: undefined DOT Split on string
x.go:3: illegal types for operand: AS
	undefined
wreck.mtv=;

BUG=1938751
R=ken
OCL=30766
CL=30766
parent 4bce6d45
...@@ -84,7 +84,7 @@ convlit1(Node *n, Type *t, int explicit) ...@@ -84,7 +84,7 @@ convlit1(Node *n, Type *t, int explicit)
return; return;
} }
// avoided repeated calculations, errors // avoided repeated calculations, errors
if(cvttype(n->type, t)) { if(cvttype(n->type, t) == 1) {
n->type = t; n->type = t;
return; return;
} }
...@@ -603,8 +603,7 @@ ret: ...@@ -603,8 +603,7 @@ ret:
n->val = v; n->val = v;
// check range. // check range.
lno = lineno; lno = setlineno(n);
lineno = n->lineno;
overflow(v, n->type); overflow(v, n->type);
lineno = lno; lineno = lno;
......
...@@ -106,7 +106,14 @@ setlineno(Node *n) ...@@ -106,7 +106,14 @@ setlineno(Node *n)
int32 lno; int32 lno;
lno = lineno; lno = lineno;
if(n != N && n->op != ONAME) { if(n != N)
switch(n->op) {
case ONAME:
case OTYPE:
case OPACK:
case OLITERAL:
break;
default:
lineno = n->lineno; lineno = n->lineno;
if(lineno == 0) { if(lineno == 0) {
if(debug['K']) if(debug['K'])
......
...@@ -123,15 +123,7 @@ loop: ...@@ -123,15 +123,7 @@ loop:
return; return;
more = N; more = N;
switch(n->op) { setlineno(n);
case ONAME: // one only; lineno isn't right for right now
case OPACK:
case OTYPE:
case OLITERAL:
break;
default:
lineno = n->lineno;
}
switch(n->op) { switch(n->op) {
...@@ -253,6 +245,13 @@ loop: ...@@ -253,6 +245,13 @@ loop:
fatal("walktype: switch 1 unknown op %N", n); fatal("walktype: switch 1 unknown op %N", n);
goto ret; goto ret;
case OTYPE:
if(!n->diag) {
n->diag = 1;
yyerror("type %T used as expression", n->type);
}
goto ret;
case ODCL: case ODCL:
goto ret; goto ret;
...@@ -1799,8 +1798,12 @@ walkdot(Node *n) ...@@ -1799,8 +1798,12 @@ walkdot(Node *n)
n->op = ODOTPTR; n->op = ODOTPTR;
} }
if(!lookdot(n, t)) if(!lookdot(n, t)) {
yyerror("undefined DOT %S on %T", n->right->sym, n->left->type); if(!n->diag) {
n->diag = 1;
yyerror("undefined DOT %S on %T", n->right->sym, n->left->type);
}
}
} }
Node* Node*
......
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