diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-07-03 23:40:47 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-07-03 23:40:47 -0400 |
| commit | bfe0bf695b8471a5553bf5cdf5fc527c42eda1e8 (patch) | |
| tree | 028b4b233b826f31a6ffc95c8d58a7314529c904 /test | |
| parent | c2cf04086a74a3c0ac31dbc1b8d01de76988c7ae (diff) | |
| parent | a1b952f4b03b7becad85ad47f96a75c0be620cf8 (diff) | |
| download | zig-bfe0bf695b8471a5553bf5cdf5fc527c42eda1e8.tar.gz zig-bfe0bf695b8471a5553bf5cdf5fc527c42eda1e8.zip | |
Merge branch 'impl-1107' of https://github.com/emekoi/zig into emekoi-impl-1107
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 c411ba46f6..c6852621e3 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -6073,4 +6073,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 }); +} |
