From 769919c4eeedaf5798688708fb0334fcb9607b57 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Mon, 6 Jul 2009 16:05:48 -0700 Subject: [PATCH] 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 --- src/cmd/gc/swt.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/cmd/gc/swt.c b/src/cmd/gc/swt.c index 486e181b14..b320475ec9 100644 --- a/src/cmd/gc/swt.c +++ b/src/cmd/gc/swt.c @@ -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; inode; + 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; } -- 2.48.1