shithub: mc

Download patch

ref: b778de26a0bcc80aa49f111b8333511511073634
parent: 62ea6ad22c399c646e396efe264c8314f14027a3
author: Ori Bernstein <ori@eigenstate.org>
date: Tue Dec 29 19:48:49 EST 2015

Missing a cast to fold to the right type.

	The length of an array should always be converted to the
	type used for indexing.

	Fixes #31

--- a/mi/fold.c
+++ b/mi/fold.c
@@ -216,8 +216,10 @@
 	case Omemb:
 		t = tybase(exprtype(args[0]));
 		/* we only fold lengths right now */
-		if (t->type == Tyarray && !strcmp(namestr(args[1]), "len"))
-			r = t->asize;
+		if (t->type == Tyarray && !strcmp(namestr(args[1]), "len")) {
+			r = mkexpr(n->loc, Ocast, t->asize);
+			r->expr.type = exprtype(n);
+		}
 		break;
 	case Oarr:
 		qsort(n->expr.args, n->expr.nargs, sizeof(Node*), idxcmp);