shithub: mc

Download patch

ref: 0b5023c54b5310de851219ebbcd5f27876a005fb
parent: b35f5329f0943d23c40ea3380fd8af3bc617cb33
author: Ori Bernstein <ori@eigenstate.org>
date: Tue Feb 23 17:10:28 EST 2016

Fix delayed check ordering.

	Outer structs define the type of the inner structs, so we
	need to add them to the delayed check list before the outer
	struct, otherwise the type may not get inferred correctly
	in the face of defaulting.

	Fixes #90

--- a/parse/infer.c
+++ b/parse/infer.c
@@ -1198,6 +1198,8 @@
 	size_t i;
 
 	*isconst = 1;
+	/* we want to check outer nodes before inner nodes when unifying nested structs */
+	delayedcheck(st, n, curstab());
 	for (i = 0; i < n->expr.nargs; i++) {
 		infernode(st, &n->expr.args[i], NULL, NULL);
 		if (!n->expr.args[i]->expr.isconst)
@@ -1204,7 +1206,6 @@
 			*isconst = 0;
 	}
 	settype(st, n, mktyvar(n->loc));
-	delayedcheck(st, n, curstab());
 }
 
 static int64_t arraysize(Inferstate *st, Node *n)
@@ -2088,8 +2089,8 @@
 		}
 
 		if (!et)
-			fatal(n, "could not find member %s in struct %s, near %s", namestr(name),
-					tystr(t), ctxstr(st, n));
+			fatal(n, "could not find member %s in struct %s, near %s",
+				namestr(name), tystr(t), ctxstr(st, n));
 
 		unify(st, val, et, type(st, val));
 	}