| ... | ... | @@ -731,3 +731,41 @@ test "peer result null and comptime_int" { |
| 731 | 731 | expect(S.blah(-10).? == -1); |
| 732 | 732 | comptime expect(S.blah(-10).? == -1); |
| 733 | 733 | } |
| 734 | |
| 735 | test "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 | |
| 752 | test "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 | |
| 767 | test "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 | } |