authorgravatar for pentuppup@noreply.codeberg.orgpentuppup <pentuppup@noreply.codeberg.org> 2026-04-02 14:57:33-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-04-08 15:22:48+02:00
log6193470ceea89a986eb38a9abd7548118d18aab7
treeda3bf00b07993fc7c182e3f1b617407ac0eb95c0
parent86853ba0a49579fdd8a41ac2c243075d8e51d83c

error on tuples in extern contexts


3 files changed, 17 insertions(+), 0 deletions(-)

src/Sema.zig+4
......@@ -25262,6 +25262,10 @@ pub fn explainWhyTypeIsNotExtern(
2526225262 }
2526325263 },
2526425264 .@"struct" => {
25265 if (ty.isTuple(zcu)) {
25266 return sema.errNote(src_loc, msg, "tuples have no guaranteed in-memory representation", .{});
25267 }
25268
2526525269 const struct_obj = zcu.intern_pool.loadStructType(ty.toIntern());
2526625270 switch (struct_obj.layout) {
2526725271 .auto => try sema.errNote(src_loc, msg, "struct with automatic layout has no guaranteed in-memory representation", .{}),
src/Type.zig+1
......@@ -3186,6 +3186,7 @@ pub fn validateExtern(ty: Type, position: ExternPosition, zcu: *const Zcu) bool
31863186 };
31873187 },
31883188 .@"struct" => {
3189 if (ty.isTuple(zcu)) return false;
31893190 const struct_obj = zcu.intern_pool.loadStructType(ty.toIntern());
31903191 return switch (struct_obj.layout) {
31913192 .auto => false,
test/cases/compile_errors/tuple_in_extern_context.zig created+12
......@@ -0,0 +1,12 @@
1const S = extern struct {
2 f: struct { u32 },
3};
4
5comptime {
6 _ = @sizeOf(S);
7}
8
9// error
10//
11// :2:8: error: extern structs cannot contain fields of type 'struct { u32 }'
12// :2:8: note: tuples have no guaranteed in-memory representation