summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2009-06-25 16:32:33 -0700
committerRuss Cox <rsc@golang.org>2009-06-25 16:32:33 -0700
commit69a4a5031b0c710664faaac271eca8ac383f17cd (patch)
tree2b3eeb6527a9f7303c730357a9d190a2aee6769b /src
parentaba3b944e7aa3de7f76d449c6cdec249e8b7dae6 (diff)
downloadgolang-69a4a5031b0c710664faaac271eca8ac383f17cd.tar.gz
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
Diffstat (limited to 'src')
-rw-r--r--src/cmd/gc/const.c5
-rw-r--r--src/cmd/gc/subr.c9
-rw-r--r--src/cmd/gc/walk.c25
3 files changed, 24 insertions, 15 deletions
diff --git a/src/cmd/gc/const.c b/src/cmd/gc/const.c
index 98245fbc4..5ce4ebee7 100644
--- a/src/cmd/gc/const.c
+++ b/src/cmd/gc/const.c
@@ -84,7 +84,7 @@ convlit1(Node *n, Type *t, int explicit)
return;
}
// avoided repeated calculations, errors
- if(cvttype(n->type, t)) {
+ if(cvttype(n->type, t) == 1) {
n->type = t;
return;
}
@@ -603,8 +603,7 @@ ret:
n->val = v;
// check range.
- lno = lineno;
- lineno = n->lineno;
+ lno = setlineno(n);
overflow(v, n->type);
lineno = lno;
diff --git a/src/cmd/gc/subr.c b/src/cmd/gc/subr.c
index b2b8e77d6..4f646fbc1 100644
--- a/src/cmd/gc/subr.c
+++ b/src/cmd/gc/subr.c
@@ -106,7 +106,14 @@ setlineno(Node *n)
int32 lno;
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;
if(lineno == 0) {
if(debug['K'])
diff --git a/src/cmd/gc/walk.c b/src/cmd/gc/walk.c
index 18fc7f335..50e333797 100644
--- a/src/cmd/gc/walk.c
+++ b/src/cmd/gc/walk.c
@@ -123,15 +123,7 @@ loop:
return;
more = N;
- switch(n->op) {
- case ONAME: // one only; lineno isn't right for right now
- case OPACK:
- case OTYPE:
- case OLITERAL:
- break;
- default:
- lineno = n->lineno;
- }
+ setlineno(n);
switch(n->op) {
@@ -253,6 +245,13 @@ loop:
fatal("walktype: switch 1 unknown op %N", n);
goto ret;
+ case OTYPE:
+ if(!n->diag) {
+ n->diag = 1;
+ yyerror("type %T used as expression", n->type);
+ }
+ goto ret;
+
case ODCL:
goto ret;
@@ -1799,8 +1798,12 @@ walkdot(Node *n)
n->op = ODOTPTR;
}
- if(!lookdot(n, t))
- yyerror("undefined DOT %S on %T", n->right->sym, n->left->type);
+ if(!lookdot(n, t)) {
+ if(!n->diag) {
+ n->diag = 1;
+ yyerror("undefined DOT %S on %T", n->right->sym, n->left->type);
+ }
+ }
}
Node*