ref: c3955db0543c35b4adb822f5beca686e8c3726ef
parent: f1383ff55a560228d15cf59dabba30dee3e3daeb
author: Ori Bernstein <[email protected]>
date: Mon Oct 21 17:37:23 EDT 2013
Add tests for the new match types
--- a/6/simp.c
+++ b/6/simp.c
@@ -502,7 +502,7 @@
case Tyvoid: case Tybad: case Tyvalist: case Tyvar:
case Typaram: case Tyunres: case Tyname: case Ntypes:
/* Should never show up */
- case Tyslice: case Tyarray:
+ case Tyslice:
die("Unsupported type for compare");
break;
case Tybool: case Tychar: case Tybyte:
@@ -515,9 +515,10 @@
v->expr.type = mktype(pat->line, Tybool);
cjmp(s, v, iftrue, iffalse);
break;
- /* We got lucky. The structure of tuple and struct literals is the
- * same, so long as we don't inspect the type */
- case Tystruct: case Tytuple:
+ /* We got lucky. The structure of tuple, array, and struct literals
+ * is the same, so long as we don't inspect the type, so we can
+ * share the code*/
+ case Tystruct: case Tytuple: case Tyarray:
patarg = pat->expr.args;
off = 0;
for (i = 0; i < pat->expr.nargs; i++) {
--- /dev/null
+++ b/test/matcharray.myr
@@ -1,0 +1,13 @@
+use std
+
+const main = {
+ var v = [2, 40, 10]
+
+ match v
+ [x, y, 10]:
+ -> x + y
+ ;;
+ _: std.die("Wat");;
+ ;;
+ -> 0
+}
--- /dev/null
+++ b/test/matchstruct.myr
@@ -1,0 +1,24 @@
+use std
+
+type t = struct
+ v1 : int
+ v2 : int
+ v3 : int
+;;
+
+const main = {
+ var v : t
+
+ v.v1 = 2
+ v.v2 = 40
+ v.v3 = 10
+ match v
+ [.v1 = x,
+ .v2 = y,
+ .v3 = 10]:
+ -> x + y
+ ;;
+ _: std.die("Wat");;
+ ;;
+ -> 0
+}
--- a/test/tests
+++ b/test/tests
@@ -83,6 +83,7 @@
B matchunion E 84
B matchtup E 42
B matchstruct E 42
+B matcharray E 42
B matchargunion E 69
B matchunion_sl P foo
B matchbind E 8