From 69b587c1d389808e55846cadd8eec5b9fd4bc64a Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 9 Dec 2019 15:22:44 -0500 Subject: [PATCH] add regression cases for now-passing tests closes #2749 --- test/stage1/behavior/cast.zig | 38 +++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/test/stage1/behavior/cast.zig b/test/stage1/behavior/cast.zig index 02a671f9fa..05749142c6 100644 --- a/test/stage1/behavior/cast.zig +++ b/test/stage1/behavior/cast.zig @@ -731,3 +731,41 @@ test "peer result null and comptime_int" { expect(S.blah(-10).? == -1); comptime expect(S.blah(-10).? == -1); } + +test "peer type resolution implicit cast to return type" { + const S = struct { + fn doTheTest() void { + for ("hello") |c| _ = f(c); + } + fn f(c: u8) []const u8 { + return switch (c) { + 'h', 'e' => &[_]u8{c}, // should cast to slice + 'l', ' ' => &[_]u8{ c, '.' }, // should cast to slice + else => ([_]u8{c})[0..], // is a slice + }; + } + }; + S.doTheTest(); + comptime S.doTheTest(); +} + +test "peer type resolution implicit cast to variable type" { + const S = struct { + fn doTheTest() void { + var x: []const u8 = undefined; + for ("hello") |c| x = switch (c) { + 'h', 'e' => &[_]u8{c}, // should cast to slice + 'l', ' ' => &[_]u8{ c, '.' }, // should cast to slice + else => ([_]u8{c})[0..], // is a slice + }; + } + }; + S.doTheTest(); + comptime S.doTheTest(); +} + +test "variable initialization uses result locations properly with regards to the type" { + var b = true; + const x: i32 = if (b) 1 else 2; + expect(x == 1); +}