authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-12-09 15:22:44-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-12-09 15:23:51-05:00
log69b587c1d389808e55846cadd8eec5b9fd4bc64a
tree1d143dc80e1bcab64e3eac893f2eca0dae68a133
parent5d82744f1cb3ea66c20fc377d0237a50ccbcf81e
signature Commit is signed but in an unrecognized format.

add regression cases for now-passing tests

closes #2749

1 files changed, 38 insertions(+), 0 deletions(-)

test/stage1/behavior/cast.zig+38
......@@ -731,3 +731,41 @@ test "peer result null and comptime_int" {
731731 expect(S.blah(-10).? == -1);
732732 comptime expect(S.blah(-10).? == -1);
733733}
734
735test "peer type resolution implicit cast to return type" {
736 const S = struct {
737 fn doTheTest() void {
738 for ("hello") |c| _ = f(c);
739 }
740 fn f(c: u8) []const u8 {
741 return switch (c) {
742 'h', 'e' => &[_]u8{c}, // should cast to slice
743 'l', ' ' => &[_]u8{ c, '.' }, // should cast to slice
744 else => ([_]u8{c})[0..], // is a slice
745 };
746 }
747 };
748 S.doTheTest();
749 comptime S.doTheTest();
750}
751
752test "peer type resolution implicit cast to variable type" {
753 const S = struct {
754 fn doTheTest() void {
755 var x: []const u8 = undefined;
756 for ("hello") |c| x = switch (c) {
757 'h', 'e' => &[_]u8{c}, // should cast to slice
758 'l', ' ' => &[_]u8{ c, '.' }, // should cast to slice
759 else => ([_]u8{c})[0..], // is a slice
760 };
761 }
762 };
763 S.doTheTest();
764 comptime S.doTheTest();
765}
766
767test "variable initialization uses result locations properly with regards to the type" {
768 var b = true;
769 const x: i32 = if (b) 1 else 2;
770 expect(x == 1);
771}