aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authoremekoi <emekankurumeh@outlook.com>2019-07-03 13:12:14 -0500
committeremekoi <emekankurumeh@outlook.com>2019-07-03 13:12:14 -0500
commita1b952f4b03b7becad85ad47f96a75c0be620cf8 (patch)
tree3f768d24855ae5183d5a9835a07eda7e969de948 /test
parent2d85ff94653457ea12cd9ab0984ab3b13c9b41e5 (diff)
downloadzig-a1b952f4b03b7becad85ad47f96a75c0be620cf8.tar.gz
zig-a1b952f4b03b7becad85ad47f96a75c0be620cf8.zip
added tests for #1107 and a note in the reference
Diffstat (limited to 'test')
-rw-r--r--test/compile_errors.zig17
-rw-r--r--test/stage1/behavior/switch.zig18
2 files changed, 35 insertions, 0 deletions
diff --git a/test/compile_errors.zig b/test/compile_errors.zig
index 94cd152eb7..592870c678 100644
--- a/test/compile_errors.zig
+++ b/test/compile_errors.zig
@@ -6048,4 +6048,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
"tmp.zig:5:30: error: expression value is ignored",
"tmp.zig:9:30: error: expression value is ignored",
);
+
+ cases.add(
+ "capture group on switch prong with different payloads",
+ \\const Union = union(enum) {
+ \\ A: usize,
+ \\ B: isize,
+ \\};
+ \\comptime {
+ \\ var u = Union{ .A = 8 };
+ \\ switch (u) {
+ \\ .A, .B => |e| unreachable,
+ \\ }
+ \\}
+ ,
+ "tmp.zig:8:20: error: switch prong contains cases with different payloads",
+ "tmp.zig:8:20: note: payload types are usize and isize",
+ );
}
diff --git a/test/stage1/behavior/switch.zig b/test/stage1/behavior/switch.zig
index 12e026d0ba..2b7422fa6d 100644
--- a/test/stage1/behavior/switch.zig
+++ b/test/stage1/behavior/switch.zig
@@ -391,3 +391,21 @@ test "switch with null and T peer types and inferred result location type" {
S.doTheTest(1);
comptime S.doTheTest(1);
}
+
+test "switch prongs with cases with identical payloads" {
+ const Union = union(enum) {
+ A: usize,
+ B: isize,
+ C: usize,
+ };
+ const S = struct {
+ fn doTheTest(u: Union) void {
+ switch (u) {
+ .A, .C => |e| expect(@typeOf(e) == usize),
+ .B => |e| expect(@typeOf(e) == isize),
+ }
+ }
+ };
+ S.doTheTest(Union{ .A = 8 });
+ comptime S.doTheTest(Union{ .B = -8 });
+}