ref: 1342e9853431adbf651c5a867396c02f87d51144
parent: de19a8fec7353f9e81a3c4660dd314d5cd15fd02
author: Ori Bernstein <ori@eigenstate.org>
date: Mon Feb 8 09:28:06 EST 2016
Fix mistake in folding. x % 0 is crash. x % 1 is 0.
--- a/parse/fold.c
+++ b/parse/fold.c
@@ -182,9 +182,12 @@
r = val(n->loc, a / b, exprtype(n));
break;
case Omod:
- /* x%1 = x */
+ /* x%0 = error */
if (isintval(args[1], 0))
- r = args[0];
+ fatal(args[1], "division by zero");
+ /* x%1 = 0 */
+ if (isintval(args[1], 1))
+ r = val(n->loc, 0, exprtype(n));
if (getintlit(args[0], &a) && getintlit(args[1], &b))
r = val(n->loc, a % b, exprtype(n));
break;