ref: c525bc13562d68ef0aa709b5ca4bcc1cfc156397
parent: 7bca94e234b70a13a93c77b3e4801368ea173d3d
author: Ori Bernstein <[email protected]>
date: Mon Feb 25 12:10:48 EST 2013
Add tests for big union argument matching. We want to support things like putting strings into them.
--- a/6/simp.c
+++ b/6/simp.c
@@ -479,7 +479,13 @@
case Tyint64: case Tyuint64: case Tylong: case Tyulong:
case Tyfloat32: case Tyfloat64:
case Tyslice: case Tyarray: case Tytuple: case Tystruct:
- die("Unsupported type for compare");
+ if (exprop(pat) == Ovar && !decls[pat->expr.did]->decl.isconst) {
+ v = assign(s, pat, val);
+ append(s, v);
+ jmp(s, iftrue);
+ } else {
+ die("Unsupported type for compare");
+ }
break;
case Tybool: case Tychar: case Tybyte:
case Tyint8: case Tyint16: case Tyint32: case Tyint:
--- /dev/null
+++ b/test/matchunion_sl.myr
@@ -1,0 +1,26 @@
+use std
+/* checks pattern matching on unions with arguments.
+exits with 42. */
+type u = union
+ `Int int
+ `Str byte[:]
+ `Nil
+;;
+
+const main = {
+ var v
+
+ v = `Str "foo"
+ match v
+ `Int 127:
+ -> 42
+ ;;
+ `Str s:
+ std.put("%s\n", s)
+ ;;
+ `Nil:
+ ;;
+ ;;
+ -> 0
+}
+
--- a/test/tests
+++ b/test/tests
@@ -68,6 +68,7 @@
B matchconst E 88
B matchunion E 84
B matchargunion E 69
+B matchunion_sl P foo
B matchbind E 8
B arraylit-ni E 2
# B arraylit E 3 ## BUGGERED