shithub: mc

Download patch

ref: 43a9a671c7bf82d6de25ee6f0509a8c62cf23e6e
parent: 5237b3b3f383bb9ef0e6a5defb66dbef7e19d55e
author: Ori Bernstein <[email protected]>
date: Fri Jul 20 10:49:21 EDT 2012

Add test for occurs check with types

--- a/parse/infer.c
+++ b/parse/infer.c
@@ -768,6 +768,7 @@
 
 static void checkcast(Inferstate *st, Node *n)
 {
+    /* FIXME: actually verify the casts */
 }
 
 /* returns the final type for t, after all unifications
@@ -793,7 +794,7 @@
         if (t->type == Tyarray) {
             typesub(st, t->asize);
         } else if (t->type == Tystruct) {
-            for (i = 0; i < t->nmemb; i++)
+            for (i = 0; i < t->nmemb && t->visits < st->subpass; i++)
                 typesub(st, t->sdecls[i]);
         } else if (t->type == Tyunion) {
             for (i = 0; i < t->nmemb; i++) {
@@ -831,7 +832,7 @@
         memb = st->postcheck[i]->expr.args[1];
 
         found = 0;
-        t = tf(st, type(st, aggr));
+        t = tybase(tf(st, type(st, aggr)));
         if (t->type == Tyslice || t->type == Tyarray) {
             if (!strcmp(namestr(memb), "len")) {
                 constrain(n, type(st, n), cstrtab[Tcnum]);
@@ -840,9 +841,8 @@
                 found = 1;
             }
         } else {
-            t = tybase(t);
             if (t->type == Typtr)
-                t = tf(st, t->sub[0]);
+                t = tybase(tf(st, t->sub[0]));
             nl = t->sdecls;
             for (j = 0; j < t->nmemb; j++) {
                 if (!strcmp(namestr(memb), declname(nl[j]))) {
--- a/test/tests
+++ b/test/tests
@@ -57,6 +57,7 @@
 F infermismatch
 F flow
 F occur
+F tyoccur
 F union-extraarg
 F union-missingarg
 F match-badtypes
--- /dev/null
+++ b/test/tyoccur.myr
@@ -1,0 +1,5 @@
+type t = struct
+	memb : t
+;;
+
+var v : t