| author | |
| committer | |
| log | 6193470ceea89a986eb38a9abd7548118d18aab7 |
| tree | da3bf00b07993fc7c182e3f1b617407ac0eb95c0 |
| parent | 86853ba0a49579fdd8a41ac2c243075d8e51d83c |
3 files changed, 17 insertions(+), 0 deletions(-)
src/Sema.zig+4| ... | @@ -25262,6 +25262,10 @@ pub fn explainWhyTypeIsNotExtern( | ... | @@ -25262,6 +25262,10 @@ pub fn explainWhyTypeIsNotExtern( |
| 25262 | } | 25262 | } |
| 25263 | }, | 25263 | }, |
| 25264 | .@"struct" => { | 25264 | .@"struct" => { |
| 25265 | if (ty.isTuple(zcu)) { | ||
| 25266 | return sema.errNote(src_loc, msg, "tuples have no guaranteed in-memory representation", .{}); | ||
| 25267 | } | ||
| 25268 | |||
| 25265 | const struct_obj = zcu.intern_pool.loadStructType(ty.toIntern()); | 25269 | const struct_obj = zcu.intern_pool.loadStructType(ty.toIntern()); |
| 25266 | switch (struct_obj.layout) { | 25270 | switch (struct_obj.layout) { |
| 25267 | .auto => try sema.errNote(src_loc, msg, "struct with automatic layout has no guaranteed in-memory representation", .{}), | 25271 | .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 | ... | @@ -3186,6 +3186,7 @@ pub fn validateExtern(ty: Type, position: ExternPosition, zcu: *const Zcu) bool |
| 3186 | }; | 3186 | }; |
| 3187 | }, | 3187 | }, |
| 3188 | .@"struct" => { | 3188 | .@"struct" => { |
| 3189 | if (ty.isTuple(zcu)) return false; | ||
| 3189 | const struct_obj = zcu.intern_pool.loadStructType(ty.toIntern()); | 3190 | const struct_obj = zcu.intern_pool.loadStructType(ty.toIntern()); |
| 3190 | return switch (struct_obj.layout) { | 3191 | return switch (struct_obj.layout) { |
| 3191 | .auto => false, | 3192 | .auto => false, |
test/cases/compile_errors/tuple_in_extern_context.zig created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | const S = extern struct { | ||
| 2 | f: struct { u32 }, | ||
| 3 | }; | ||
| 4 | |||
| 5 | comptime { | ||
| 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 | ||