Commit 769919c4 authored by Russ Cox's avatar Russ Cox

better error message + line numbers

package main
func main() {
       var x interface{};
       switch x {
       case 41:
       case "b":
       }
}

before:
x.go:5: fatal error: exprcmp

now:
x.go:5: illegal types for operand: EQ
	interface { }
	int
x.go:6: illegal types for operand: EQ
	interface { }
	string

R=ken
OCL=31217
CL=31219
parent 4793400b
...@@ -124,8 +124,12 @@ exprcmp(Case *c1, Case *c2) ...@@ -124,8 +124,12 @@ exprcmp(Case *c1, Case *c2)
n2 = c2->node->left; n2 = c2->node->left;
ct = n1->val.ctype; ct = n1->val.ctype;
if(ct != n2->val.ctype) if(ct != n2->val.ctype) {
fatal("exprcmp"); // invalid program, but return a sort
// order so that we can give a better
// error later.
return ct - n2->val.ctype;
}
// sort by constant value // sort by constant value
n = 0; n = 0;
...@@ -323,7 +327,7 @@ loop: ...@@ -323,7 +327,7 @@ loop:
fatal("walkcases: not case %O\n", n->op); fatal("walkcases: not case %O\n", n->op);
if(n->left != N) { if(n->left != N) {
setlineno(n->left); setlineno(n);
place = call(n->left, place, arg); place = call(n->left, place, arg);
} }
n = listnext(&save); n = listnext(&save);
...@@ -527,12 +531,13 @@ exprbsw(Case *c0, int ncase, int arg) ...@@ -527,12 +531,13 @@ exprbsw(Case *c0, int ncase, int arg)
Node *cas; Node *cas;
Node *a, *n; Node *a, *n;
Case *c; Case *c;
int i, half; int i, half, lno;
cas = N; cas = N;
if(ncase < Ncase) { if(ncase < Ncase) {
for(i=0; i<ncase; i++) { for(i=0; i<ncase; i++) {
n = c0->node; n = c0->node;
lno = setlineno(n);
switch(arg) { switch(arg) {
case Strue: case Strue:
...@@ -556,6 +561,7 @@ exprbsw(Case *c0, int ncase, int arg) ...@@ -556,6 +561,7 @@ exprbsw(Case *c0, int ncase, int arg)
cas = list(cas, a); cas = list(cas, a);
c0 = c0->link; c0 = c0->link;
lineno = lno;
} }
return cas; return cas;
} }
......
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