diff options
| author | emekoi <emekankurumeh@outlook.com> | 2019-07-03 13:12:14 -0500 |
|---|---|---|
| committer | emekoi <emekankurumeh@outlook.com> | 2019-07-03 13:12:14 -0500 |
| commit | a1b952f4b03b7becad85ad47f96a75c0be620cf8 (patch) | |
| tree | 3f768d24855ae5183d5a9835a07eda7e969de948 /test | |
| parent | 2d85ff94653457ea12cd9ab0984ab3b13c9b41e5 (diff) | |
| download | zig-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.zig | 17 | ||||
| -rw-r--r-- | test/stage1/behavior/switch.zig | 18 |
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 }); +} |
