aboutsummaryrefslogtreecommitdiff
path: root/src/analyze.cpp
diff options
context:
space:
mode:
authorLemonBoy <thatlemon@gmail.com>2019-09-01 19:47:58 +0200
committerAndrew Kelley <andrew@ziglang.org>2019-09-05 13:07:04 -0400
commit8e3c56b912b7eb6ee551b7e427adbaae0bdcd408 (patch)
tree9ecd46b466947437e23e4d759713d9dab4161cd9 /src/analyze.cpp
parent0107b19124255179a48cd605f31ed57d5ade28e7 (diff)
downloadzig-8e3c56b912b7eb6ee551b7e427adbaae0bdcd408.tar.gz
zig-8e3c56b912b7eb6ee551b7e427adbaae0bdcd408.zip
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
Diffstat (limited to 'src/analyze.cpp')
-rw-r--r--src/analyze.cpp42
1 files changed, 19 insertions, 23 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp
index 5003756be7..386ee4ec46 100644
--- a/src/analyze.cpp
+++ b/src/analyze.cpp
@@ -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;
- }
-
- if ((err = type_resolve(g, field_type, ResolveStatusSizeKnown))) {
- 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 (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;
}