shithub: mc

Download patch

ref: 3aa6af831c0a5da56c6e5d8f610a2dca6693670e
parent: be5462a429323b0c69e9cb4061bdc520be9727c1
author: Ori Bernstein <[email protected]>
date: Tue Nov 4 17:29:40 EST 2014

Fix constant patterns for matching.

--- a/mi/match.c
+++ b/mi/match.c
@@ -95,12 +95,6 @@
 
 static Dtree *addwild(Dtree *t, Node *pat, Node *val, Node ***cap, size_t *ncap)
 {
-    Node *dcl;
-
-    dcl = decls[pat->expr.did];
-    /* FIXME: Avoid duplicate constants */
-    if (dcl->decl.isconst)
-        return NULL;
     if (t->any)
         return t->any;
     t->any = mkdtree();
@@ -182,12 +176,17 @@
 static Dtree *addpat(Dtree *t, Node *pat, Node *val, Node ***cap, size_t *ncap)
 {
     Dtree *ret;
+    Node *dcl;
 
     if (pat == NULL)
         return t;
     switch (exprop(pat)) {
         case Ovar:
-            ret = addwild(t, pat, val, cap, ncap);
+            dcl = decls[pat->expr.did];
+            if (dcl->decl.isconst)
+                ret = addpat(t, dcl->decl.init, val, cap, ncap);
+            else
+                ret = addwild(t, pat, val, cap, ncap);
             break;
         case Oucon:
             ret = addunion(t, pat, val, cap, ncap);
--- a/test/matchconst.myr
+++ b/test/matchconst.myr
@@ -14,5 +14,6 @@
 	| Ca: 	std.exit(123)
 	| Cb:	std.exit(88)
 	| Cc:	std.exit(42)
+	| _:	std.die("Impossible match failure in pattern\n")
 	;;
 }