shithub: mc

Download patch

ref: 01c7435a00df771e724b857fc4d5d5c2c0730734
parent: b0886832a75e9d63f49cb878ed8abc56f37120c0
author: Ori Bernstein <[email protected]>
date: Wed Aug 7 13:02:38 EDT 2013

Fix pattern matching union variables.

    We crashed on them because never in my wildest dreams did I think
    that we'd want to create a union variable on the LHS of the match,
    instead of a union literal.

--- a/6/simp.c
+++ b/6/simp.c
@@ -502,23 +502,30 @@
             }
             break;
         case Tyunion:
-            uc = finducon(pat);
-            if (!uc)
-                uc = finducon(val);
-            deeper = genlbl();
+            if (exprop(pat) == Ovar && !decls[pat->expr.did]->decl.isconst) {
+                v = assign(s, pat, val);
+                append(s, v);
+                jmp(s, iftrue);
+            } else {
+                uc = finducon(pat);
+                if (!uc)
+                    uc = finducon(val);
 
-            x = uconid(s, pat);
-            y = uconid(s, val);
-            v = mkexpr(pat->line, Oeq, x, y, NULL);
-            v->expr.type = tyintptr;
-            cjmp(s, v, deeper, iffalse);
-            append(s, deeper);
-            if (uc->etype) {
-                pat = patval(s, pat, uc->etype);
-                val = patval(s, val, uc->etype);
-                umatch(s, pat, val, uc->etype, iftrue, iffalse);
+                deeper = genlbl();
+
+                x = uconid(s, pat);
+                y = uconid(s, val);
+                v = mkexpr(pat->line, Oeq, x, y, NULL);
+                v->expr.type = tyintptr;
+                cjmp(s, v, deeper, iffalse);
+                append(s, deeper);
+                if (uc->etype) {
+                    pat = patval(s, pat, uc->etype);
+                    val = patval(s, val, uc->etype);
+                    umatch(s, pat, val, uc->etype, iftrue, iffalse);
+                }
+                break;
             }
-            break;
     }
 }