diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-09-05 14:50:27 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-09-05 14:56:52 -0400 |
| commit | 2045b4d93240cd95eee7143f2cfc360eb63c5802 (patch) | |
| tree | 5ae5a1a453ecb8a82535b1be89822029606a9283 /test | |
| parent | 8f0df86937e140c11a1efc9f94c8ac0bd1b02e2c (diff) | |
| download | zig-2045b4d93240cd95eee7143f2cfc360eb63c5802.tar.gz zig-2045b4d93240cd95eee7143f2cfc360eb63c5802.zip | |
prefer result type casting to peer type resolution
See #2749
Diffstat (limited to 'test')
| -rw-r--r-- | test/stage1/behavior/if.zig | 12 | ||||
| -rw-r--r-- | test/stage1/behavior/struct.zig | 18 |
2 files changed, 30 insertions, 0 deletions
diff --git a/test/stage1/behavior/if.zig b/test/stage1/behavior/if.zig index 70712ea85a..d299817f46 100644 --- a/test/stage1/behavior/if.zig +++ b/test/stage1/behavior/if.zig @@ -74,3 +74,15 @@ test "const result loc, runtime if cond, else unreachable" { const x = if (t) Num.Two else unreachable; if (x != .Two) @compileError("bad"); } + +test "if prongs cast to expected type instead of peer type resolution" { + const S = struct { + fn doTheTest(f: bool) void { + var x: i32 = 0; + x = if (f) 1 else 2; + expect(x == 2); + } + }; + S.doTheTest(false); + comptime S.doTheTest(false); +} diff --git a/test/stage1/behavior/struct.zig b/test/stage1/behavior/struct.zig index 8a73615715..13d2dcc733 100644 --- a/test/stage1/behavior/struct.zig +++ b/test/stage1/behavior/struct.zig @@ -640,3 +640,21 @@ test "zero-bit field in packed struct" { }; var x: S = undefined; } + +test "struct field init with catch" { + const S = struct { + fn doTheTest() void { + var x: anyerror!isize = 1; + var req = Foo{ + .field = x catch undefined, + }; + expect(req.field == 1); + } + + pub const Foo = extern struct { + field: isize, + }; + }; + S.doTheTest(); + comptime S.doTheTest(); +} |
