diff options
Diffstat (limited to 'boot/type_check.cc')
| -rw-r--r-- | boot/type_check.cc | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/boot/type_check.cc b/boot/type_check.cc index 8f7a30f..abee91f 100644 --- a/boot/type_check.cc +++ b/boot/type_check.cc @@ -911,17 +911,16 @@ namespace elna::boot } for (const field_initializer& initializer : expression->field_initializers) { - for (const auto& [field_name, field_type]: record->fields) + // An initializer for an unknown field is already reported in name + // analysis; only check the value type when the field was found. + const type field_type = lookup_field(expression->type_decoration, initializer.name()); + + if (!field_type.empty() + && !is_assignable_from(field_type, initializer.value().type_decoration)) { - if (field_name == initializer.name()) - { - if (!is_assignable_from(field_type, initializer.value().type_decoration)) - { - add_error<type_mismatch_error>( - initializer.value().position(), initializer.value().type_decoration, type_mismatch_error::expected_type{field_type}); - } - break; - } + add_error<type_mismatch_error>( + initializer.value().position(), initializer.value().type_decoration, + type_mismatch_error::expected_type{field_type}); } } } |
