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:
Jacob Young 2023-07-27 22:40:54 -04:00
parent 20f4216af5
commit c80609dfec
2 changed files with 17 additions and 1 deletions

View File

@ -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| {

View File

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