shithub: mc

Download patch

ref: a4a2135136d585cae794fa261d549f91ca4510a7
parent: 5269edd399f1b55f98e10fc5e809e22bec6c7bb1
author: Ori Bernstein <ori@eigenstate.org>
date: Mon Mar 14 19:53:21 EDT 2016

Error if we infer a struct literal as a non-struct

	Fixes #94
	Fixes #105

--- a/parse/infer.c
+++ b/parse/infer.c
@@ -2053,17 +2053,17 @@
 	size_t i, j;
 
 	t = tybase(tf(st, n->lit.type));
-	if (t->type != Tystruct) {
-		/*
-		 * If we haven't inferred the type, and it's inside another struct,
-		 * we'll eventually get to it.
-		 *
-		 * If, on the other hand, it is genuinely underspecified, we'll give
-		 * a better error on it later.
-		 */
+	/*
+	 * If we haven't inferred the type, and it's inside another struct,
+	 * we'll eventually get to it.
+	 *
+	 * If, on the other hand, it is genuinely underspecified, we'll give
+	 * a better error on it later.
+	 */
+	if (t->type == Tyvar)
 		return;
-	}
-
+	if (t->type != Tystruct)
+		fatal(n, "struct literal is used as non struct type %s", tystr(n->lit.type));
 	for (i = 0; i < n->expr.nargs; i++) {
 		val = n->expr.args[i];
 		name = val->expr.idx;