When re-declaring, find the original decl of an associated function in an interface (#6688)

Functions in an interface definition are wrapped in an AssociatedEntity
instruction, which the logic for finding a previous declaration must
unwrap to find the FunctionDecl.

This is controlled by the NameScope::is_interface_definition() flag,
which is true for interfaces, and causes this extra wrapping to occur
when adding the function to the scope.
This commit is contained in:
Dana Jansens
2026-02-04 19:22:35 +00:00
committed by GitHub
parent 45ca3d28f5
commit f63d0a6266
5 changed files with 70 additions and 106 deletions
+9
View File
@@ -195,6 +195,15 @@ static auto TryMergeRedecl(Context& context, Parse::AnyFunctionDeclId node_id,
auto prev_type_id = SemIR::TypeId::None;
auto prev_import_ir_id = SemIR::ImportIRId::None;
CARBON_KIND_SWITCH(context.insts().Get(prev_id)) {
case CARBON_KIND(SemIR::AssociatedEntity assoc_entity): {
// This is a function in an interface definition scope (see
// NameScope::is_interface_definition()).
auto function_decl =
context.insts().GetAs<SemIR::FunctionDecl>(assoc_entity.decl_id);
prev_function_id = function_decl.function_id;
prev_type_id = function_decl.type_id;
break;
}
case CARBON_KIND(SemIR::FunctionDecl function_decl): {
prev_function_id = function_decl.function_id;
prev_type_id = function_decl.type_id;