1
0
mirror of https://github.com/golang/go synced 2024-10-03 06:11:21 -06:00

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
This commit is contained in:
Russ Cox 2009-07-06 16:05:48 -07:00
parent 4793400bd1
commit 769919c4ee

View File

@ -124,8 +124,12 @@ exprcmp(Case *c1, Case *c2)
n2 = c2->node->left;
ct = n1->val.ctype;
if(ct != n2->val.ctype)
fatal("exprcmp");
if(ct != n2->val.ctype) {
// 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
n = 0;
@ -323,7 +327,7 @@ loop:
fatal("walkcases: not case %O\n", n->op);
if(n->left != N) {
setlineno(n->left);
setlineno(n);
place = call(n->left, place, arg);
}
n = listnext(&save);
@ -527,12 +531,13 @@ exprbsw(Case *c0, int ncase, int arg)
Node *cas;
Node *a, *n;
Case *c;
int i, half;
int i, half, lno;
cas = N;
if(ncase < Ncase) {
for(i=0; i<ncase; i++) {
n = c0->node;
lno = setlineno(n);
switch(arg) {
case Strue:
@ -556,6 +561,7 @@ exprbsw(Case *c0, int ncase, int arg)
cas = list(cas, a);
c0 = c0->link;
lineno = lno;
}
return cas;
}