mirror of
https://github.com/ziglang/zig.git
synced 2024-11-26 23:22:44 +00:00
Sema: don't reorder tuple fields
This conflicts with anon structs which can be in-memory coercible but are never reordered. Closes #16242
This commit is contained in:
parent
20f4216af5
commit
c80609dfec
@ -33491,7 +33491,9 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void {
|
||||
return sema.failWithOwnedErrorMsg(msg);
|
||||
}
|
||||
|
||||
if (struct_obj.layout == .Auto and mod.backendSupportsFeature(.field_reordering)) {
|
||||
if (struct_obj.layout == .Auto and !struct_obj.is_tuple and
|
||||
mod.backendSupportsFeature(.field_reordering))
|
||||
{
|
||||
const optimized_order = try mod.tmp_hack_arena.allocator().alloc(u32, struct_obj.fields.count());
|
||||
|
||||
for (struct_obj.fields.values(), 0..) |field, i| {
|
||||
|
@ -453,3 +453,17 @@ test "tuple pointer is indexable" {
|
||||
try expectEqual(@as(u32, 100), (&y)[0]);
|
||||
try expectEqual(false, (&y)[1]);
|
||||
}
|
||||
|
||||
test "coerce anon tuple to tuple" {
|
||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; // TODO
|
||||
|
||||
var x: u8 = 1;
|
||||
var y: u16 = 2;
|
||||
var t = .{ x, y };
|
||||
var s: struct { u8, u16 } = t;
|
||||
try expectEqual(x, s[0]);
|
||||
try expectEqual(y, s[1]);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user