add regression cases for now-passing tests

closes #2749
This commit is contained in:
Andrew Kelley 2019-12-09 15:22:44 -05:00
parent 5d82744f1c
commit 69b587c1d3
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9

View File

@ -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);
}