AstGen: fix result locations for elements of typed array init
Resolves: #16226
This commit is contained in:
@@ -719,3 +719,32 @@ test "pointer to array has ptr field" {
|
||||
try std.testing.expect(arr.ptr[3] == 40);
|
||||
try std.testing.expect(arr.ptr[4] == 50);
|
||||
}
|
||||
|
||||
test "discarded array init preserves result location" {
|
||||
const S = struct {
|
||||
fn f(p: *u32) u16 {
|
||||
p.* += 1;
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
var x: u32 = 0;
|
||||
_ = [2]u8{
|
||||
@intCast(S.f(&x)),
|
||||
@intCast(S.f(&x)),
|
||||
};
|
||||
|
||||
// Ensure function was run
|
||||
try expect(x == 2);
|
||||
}
|
||||
|
||||
test "array init with no result location has result type" {
|
||||
const x = .{ .foo = [2]u16{
|
||||
@intCast(10),
|
||||
@intCast(20),
|
||||
} };
|
||||
|
||||
try expect(x.foo.len == 2);
|
||||
try expect(x.foo[0] == 10);
|
||||
try expect(x.foo[1] == 20);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user