Merge pull request #23263 from mlugg/comptime-field-ptr
Sema: fix pointers to comptime fields of comptime-known aggregate pointers
This commit is contained in:
@@ -602,3 +602,21 @@ test "empty union in tuple" {
|
||||
try std.testing.expectEqualStrings("0", info.@"struct".fields[0].name);
|
||||
try std.testing.expect(@typeInfo(info.@"struct".fields[0].type) == .@"union");
|
||||
}
|
||||
|
||||
test "field pointer of underaligned tuple" {
|
||||
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
|
||||
const S = struct {
|
||||
fn doTheTest() !void {
|
||||
const T = struct { u8, u32 };
|
||||
var val: T align(2) = .{ 1, 2 };
|
||||
|
||||
comptime assert(@TypeOf(&val[0]) == *u8); // `u8` field pointer isn't overaligned
|
||||
comptime assert(@TypeOf(&val[1]) == *align(2) u32); // `u32` field pointer is correctly underaligned
|
||||
|
||||
try expect(val[0] == 1);
|
||||
try expect(val[1] == 2);
|
||||
}
|
||||
};
|
||||
try S.doTheTest();
|
||||
try comptime S.doTheTest();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user