mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 10:11:06 +01:00
Fix SemIR not showing insts used to compute FieldDecl type (#7706)
Add an `ExprRegionId` to `FieldDecl`. This required moving the `NameId` into `Field`.
This commit is contained in:
+32
-27
@@ -126,33 +126,6 @@ auto AddBindingForPattern(Context& context, SemIR::LocId name_loc,
|
||||
pattern.kind);
|
||||
}
|
||||
|
||||
// Handle non-static `var` decls in a class by creating a `FieldDecl`.
|
||||
if (InNonStaticFieldDecl(context)) {
|
||||
auto class_decl =
|
||||
context.scope_stack().TryGetCurrentScopeAs<SemIR::ClassDecl>();
|
||||
auto name_id = context.entity_names().Get(pattern.entity_name_id).name_id;
|
||||
auto& class_info = context.classes().Get(class_decl->class_id);
|
||||
auto field_type_id = GetUnboundElementType(
|
||||
context, context.types().GetTypeInstId(class_info.self_type_id),
|
||||
context.types().GetTypeInstId(binding_type_id));
|
||||
|
||||
if (name_id == SemIR::NameId::Underscore) {
|
||||
CARBON_DIAGNOSTIC(FieldNamedUnderscore, Error,
|
||||
"expected identifier in field declaration");
|
||||
context.emitter().Emit(name_loc, FieldNamedUnderscore);
|
||||
}
|
||||
|
||||
auto field_id =
|
||||
context.fields().Add({.index = SemIR::ElementIndex::None,
|
||||
.initializer_id = SemIR::InstId::None});
|
||||
auto field_decl_id = AddInst<SemIR::FieldDecl>(
|
||||
context, name_loc,
|
||||
{.type_id = field_type_id, .name_id = name_id, .field_id = field_id});
|
||||
context.field_decls_stack().AppendToTop(field_decl_id);
|
||||
|
||||
return field_decl_id;
|
||||
}
|
||||
|
||||
auto bind_id = AddInstInNoBlock(
|
||||
context, SemIR::LocIdAndInst::RuntimeVerified(
|
||||
context.sem_ir(), name_loc,
|
||||
@@ -172,6 +145,38 @@ auto AddBindingPattern(Context& context, SemIR::LocId name_loc,
|
||||
SemIR::ExprRegionId type_region_id,
|
||||
SemIR::TypeId scrutinee_type_id,
|
||||
SemIR::AnyBindingPattern pattern) -> BindingPatternInfo {
|
||||
// Handle non-static `var` decls in a class by creating a `FieldDecl`.
|
||||
if (InNonStaticFieldDecl(context)) {
|
||||
auto class_decl =
|
||||
context.scope_stack().TryGetCurrentScopeAs<SemIR::ClassDecl>();
|
||||
auto name_id = context.entity_names().Get(pattern.entity_name_id).name_id;
|
||||
auto& class_info = context.classes().Get(class_decl->class_id);
|
||||
auto field_type_id = GetUnboundElementType(
|
||||
context, context.types().GetTypeInstId(class_info.self_type_id),
|
||||
context.types().GetTypeInstId(scrutinee_type_id));
|
||||
|
||||
if (name_id == SemIR::NameId::Underscore) {
|
||||
CARBON_DIAGNOSTIC(FieldNamedUnderscore, Error,
|
||||
"expected identifier in field declaration");
|
||||
context.emitter().Emit(name_loc, FieldNamedUnderscore);
|
||||
}
|
||||
|
||||
auto field_id =
|
||||
context.fields().Add({.index = SemIR::ElementIndex::None,
|
||||
.name_id = name_id,
|
||||
.initializer_id = SemIR::InstId::None});
|
||||
auto field_decl_id =
|
||||
AddInst<SemIR::FieldDecl>(context, name_loc,
|
||||
{
|
||||
.type_id = field_type_id,
|
||||
.field_id = field_id,
|
||||
.type_region_id = type_region_id,
|
||||
});
|
||||
context.field_decls_stack().AppendToTop(field_decl_id);
|
||||
|
||||
return {.pattern_id = field_decl_id, .bind_id = field_decl_id};
|
||||
}
|
||||
|
||||
auto binding_pattern_id =
|
||||
AddInst(context, SemIR::LocIdAndInst::RuntimeVerified(context.sem_ir(),
|
||||
name_loc, pattern));
|
||||
|
||||
Reference in New Issue
Block a user