1414#include " toolchain/check/merge.h"
1515#include " toolchain/check/modifiers.h"
1616#include " toolchain/check/name_component.h"
17+ #include " toolchain/parse/node_ids.h"
1718#include " toolchain/sem_ir/function.h"
1819#include " toolchain/sem_ir/ids.h"
1920#include " toolchain/sem_ir/inst.h"
@@ -53,9 +54,8 @@ auto HandleParseNode(Context& context, Parse::ClassIntroducerId node_id)
5354//
5455// If merging is successful, returns true and may update the previous class.
5556// Otherwise, returns false. Prints a diagnostic when appropriate.
56- static auto MergeClassRedecl (Context& context, SemIRLoc new_loc,
57- SemIR::Class& new_class, bool new_is_import,
58- bool new_is_definition,
57+ static auto MergeClassRedecl (Context& context, Parse::AnyClassDeclId node_id,
58+ SemIR::Class& new_class, bool new_is_definition,
5959 SemIR::ClassId prev_class_id,
6060 SemIR::ImportIRId prev_import_ir_id) -> bool {
6161 auto & prev_class = context.classes ().Get (prev_class_id);
@@ -69,7 +69,7 @@ static auto MergeClassRedecl(Context& context, SemIRLoc new_loc,
6969
7070 DiagnoseIfInvalidRedecl (
7171 context, Lex::TokenKind::Class, prev_class.name_id ,
72- RedeclInfo (new_class, new_loc , new_is_definition),
72+ RedeclInfo (new_class, node_id , new_is_definition),
7373 RedeclInfo (prev_class, prev_loc, prev_class.has_definition_started ()),
7474 prev_import_ir_id);
7575
@@ -87,12 +87,11 @@ static auto MergeClassRedecl(Context& context, SemIRLoc new_loc,
8787 prev_class.complete_type_witness_id = new_class.complete_type_witness_id ;
8888 }
8989
90- if (( prev_import_ir_id.has_value () && !new_is_import ) ||
90+ if (prev_import_ir_id.has_value () ||
9191 (prev_class.is_extern && !new_class.is_extern )) {
9292 prev_class.first_owning_decl_id = new_class.first_owning_decl_id ;
93- ReplacePrevInstForMerge (
94- context, new_class.parent_scope_id , prev_class.name_id ,
95- new_is_import ? new_loc.inst_id : new_class.first_owning_decl_id );
93+ ReplacePrevInstForMerge (context, new_class.parent_scope_id ,
94+ prev_class.name_id , new_class.first_owning_decl_id );
9695 }
9796 return true ;
9897}
@@ -165,9 +164,8 @@ static auto MergeOrAddName(Context& context, Parse::AnyClassDeclId node_id,
165164
166165 // TODO: Fix `extern` logic. It doesn't work correctly, but doesn't seem worth
167166 // ripping out because existing code may incrementally help.
168- if (MergeClassRedecl (context, node_id, class_info,
169- /* new_is_import=*/ false , is_definition, prev_class_id,
170- prev_import_ir_id)) {
167+ if (MergeClassRedecl (context, node_id, class_info, is_definition,
168+ prev_class_id, prev_import_ir_id)) {
171169 // When merging, use the existing entity rather than adding a new one.
172170 class_decl.class_id = prev_class_id;
173171 class_decl.type_id = prev.type_id ();
0 commit comments