summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2018-07-07 01:12:04 -0700
committerOri Bernstein <ori@eigenstate.org>2018-07-08 22:29:17 -0700
commitbeab0276a94c684f938ae5ea3d2c29c3dc331386 (patch)
treea61f44355a47c2e013ab36e0cf63502f59b16b2b /test
parent5d16f2c900fc1bc0b461878f5c936b969b7bee7d (diff)
downloadmc-beab0276a94c684f938ae5ea3d2c29c3dc331386.tar.gz
Fix overlapping match statements (thanks Mako)
We were overly aggressive in unifying wildcards.
Diffstat (limited to 'test')
-rw-r--r--test/matchoverwild.myr43
-rw-r--r--test/tests2
2 files changed, 45 insertions, 0 deletions
diff --git a/test/matchoverwild.myr b/test/matchoverwild.myr
new file mode 100644
index 0000000..e34e8a1
--- /dev/null
+++ b/test/matchoverwild.myr
@@ -0,0 +1,43 @@
+use std
+
+type ast = struct
+ body : op[:]
+;;
+type op = union
+ `Go int
+ `Set int
+ `Add int
+ `Mul (int, int)
+ `Read
+ `Write
+ `Loop ast
+;;
+
+const combine = {lhs : op, rhs : op
+ match (lhs, rhs)
+ | (`Add x, `Add y): -> `std.Some `Add (x + y)
+ | (`Go x, `Go y): -> `std.Some `Go (x + y)
+ | (`Go 0, _): -> `std.Some rhs
+ | (`Set x, `Add y): -> `std.Some `Set(x + y)
+ | (`Add _, `Set y): -> `std.Some rhs
+ | (`Add _, `Read): -> `std.Some rhs
+ | (`Set _, `Read): -> `std.Some rhs
+ | (`Loop _, `Loop _): -> `std.Some lhs
+ | _: -> `std.None
+ ;;
+}
+
+const main = {
+ match combine(`Add 123, `Set 246)
+ | `std.Some `Set 246:
+ /* ok */
+ | r:
+ std.fatal("bad combine {}\n", r)
+ ;;
+ match combine(`Add 123, `Add 246)
+ | `std.Some `Add 369:
+ /* ok */
+ | r:
+ std.fatal("bad combine {}\n", r)
+ ;;
+}
diff --git a/test/tests b/test/tests
index 3fa19f6..6b9cb65 100644
--- a/test/tests
+++ b/test/tests
@@ -110,6 +110,7 @@ B sizeof E 4
B gsizeof E 5
B matchint E 84
B matchconst E 88
+B matchoverwild E 0
B matchnsconst P 'matched badchar'
B matchunion E 84
B matchtup E 42
@@ -149,6 +150,7 @@ B strjoin C
B exporttrait E 0
B local-labels E 10
B empty-struct E 21
+B empty-struct E 21
F declmismatch
F infermismatch
F usedef