shithub: mc

Download patch

ref: 86176386c885b1f424d86321c06ca353842fa3b1
parent: 3aa6af831c0a5da56c6e5d8f610a2dca6693670e
author: Ori Bernstein <[email protected]>
date: Tue Nov 4 17:42:09 EST 2014

Fix clobbering match pattern type.

--- a/mi/match.c
+++ b/mi/match.c
@@ -98,6 +98,7 @@
     if (t->any)
         return t->any;
     t->any = mkdtree();
+    t->patexpr = pat;
     lappend(cap, ncap, pat);
     return t->any;
 }
@@ -134,6 +135,7 @@
     }
 
     sub = mkdtree();
+    sub->patexpr = pat;
     lappend(&t->val, &t->nval, pat);
     lappend(&t->sub, &t->nsub, sub);
     return sub;
@@ -208,7 +210,6 @@
             fatal(pat, "unsupported pattern %s of type %s", opstr(exprop(pat)), tystr(exprtype(pat)));
             break;
     }
-    ret->patexpr = pat;
     return ret;
 }
 
--- /dev/null
+++ b/test/matchexhaust.myr
@@ -1,0 +1,37 @@
+use std
+
+type u = union
+	`Foo (bool, v, bool)
+	`Bar (bool, bool)
+	`Baz bool
+	`Quux
+;;
+
+type v = union
+	`A
+	`B
+;;
+
+const main = {
+	match `Quux
+	| `Foo (true, `A, true):
+	| `Foo (true, `A, false):
+	| `Foo (true, `B, true):
+	| `Foo (true, `B, false):
+	| `Foo (false, `A, true):
+	| `Foo (false, `A, false):
+	| `Foo (false, `B, true):
+	| `Foo (false, `B, false):
+
+	| `Bar (false, false):
+	| `Bar (false, true):
+	| `Bar (true, false):
+	| `Bar (true, true):
+
+	| `Baz false:
+	| `Baz true:
+
+	| `Quux:
+	;;
+	std.put("worked\n")
+}
--- a/test/tests
+++ b/test/tests
@@ -104,6 +104,7 @@
 B matchstruct	E	42
 B matcharray	E	42
 B matchargunion	E	69
+B matchexhaust	P	worked
 B matchargstr	C
 B matchunion_sl	P	foo
 B matchbind	E	8