mirror of
https://github.com/ziglang/zig.git
synced 2026-02-14 13:30:45 +00:00
Always resolve the struct field types
Packed structs used to skip the zero-sized types and trip some assertions that expected the type reference not to be null. Fixes #3143
This commit is contained in:
parent
0107b19124
commit
8e3c56b912
@ -2043,34 +2043,30 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) {
|
||||
|
||||
|
||||
// Resolve types for fields
|
||||
if (!packed) {
|
||||
for (size_t i = 0; i < field_count; i += 1) {
|
||||
TypeStructField *field = &struct_type->data.structure.fields[i];
|
||||
ZigType *field_type = resolve_struct_field_type(g, field);
|
||||
if (field_type == nullptr) {
|
||||
struct_type->data.structure.resolve_status = ResolveStatusInvalid;
|
||||
return err;
|
||||
}
|
||||
for (size_t i = 0; i < field_count; i += 1) {
|
||||
TypeStructField *field = &struct_type->data.structure.fields[i];
|
||||
ZigType *field_type = resolve_struct_field_type(g, field);
|
||||
if (field_type == nullptr) {
|
||||
struct_type->data.structure.resolve_status = ResolveStatusInvalid;
|
||||
return err;
|
||||
}
|
||||
|
||||
if ((err = type_resolve(g, field_type, ResolveStatusSizeKnown))) {
|
||||
struct_type->data.structure.resolve_status = ResolveStatusInvalid;
|
||||
return err;
|
||||
}
|
||||
|
||||
if (struct_type->data.structure.layout == ContainerLayoutExtern &&
|
||||
!type_allowed_in_extern(g, field_type))
|
||||
{
|
||||
add_node_error(g, field->decl_node,
|
||||
buf_sprintf("extern structs cannot contain fields of type '%s'",
|
||||
buf_ptr(&field_type->name)));
|
||||
struct_type->data.structure.resolve_status = ResolveStatusInvalid;
|
||||
return ErrorSemanticAnalyzeFail;
|
||||
}
|
||||
if ((err = type_resolve(g, field_type, ResolveStatusSizeKnown))) {
|
||||
struct_type->data.structure.resolve_status = ResolveStatusInvalid;
|
||||
return err;
|
||||
}
|
||||
|
||||
if (struct_type->data.structure.layout == ContainerLayoutExtern &&
|
||||
!type_allowed_in_extern(g, field_type))
|
||||
{
|
||||
add_node_error(g, field->decl_node,
|
||||
buf_sprintf("extern structs cannot contain fields of type '%s'",
|
||||
buf_ptr(&field_type->name)));
|
||||
struct_type->data.structure.resolve_status = ResolveStatusInvalid;
|
||||
return ErrorSemanticAnalyzeFail;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return ErrorNone;
|
||||
}
|
||||
|
||||
|
||||
@ -632,3 +632,11 @@ test "for loop over pointers to struct, getting field from struct pointer" {
|
||||
};
|
||||
S.doTheTest();
|
||||
}
|
||||
|
||||
test "zero-bit field in packed struct" {
|
||||
const S = packed struct {
|
||||
x: u10,
|
||||
y: void,
|
||||
};
|
||||
var x: S = undefined;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user