ref: f82ca04d8d3197afd59f0e791fb7535265f5dac0
parent: e1a74a0d31d8aaac4528c821654cab5e9a1ef144
author: Ori Bernstein <[email protected]>
date: Wed Jan 22 21:17:43 EST 2014
Allow more foldable, constant expressions in patterns.
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -980,6 +980,22 @@
case Olit:
case Omemb:
infernode(st, n, NULL, NULL); break;
+ /* arithmetic expressions just need to be constant */
+ case Oneg:
+ case Oadd:
+ case Osub:
+ case Omul:
+ case Odiv:
+ case Obsl:
+ case Obsr:
+ case Oband:
+ case Obor:
+ case Obxor:
+ case Obnot:
+ infernode(st, n, NULL, NULL);
+ if (!n->expr.isconst)
+ fatal(n->line, "matching against non-constant expression");
+ break;
case Oucon: inferucon(st, n, &n->expr.isconst); break;
case Ovar:
s = getdcl(curstab(), args[0]);
@@ -1001,7 +1017,7 @@
n->expr.did = s->decl.did;
break;
default:
- die("Bad pattern to match against");
+ fatal(n->line, "invalid pattern");
break;
}
}