mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Refactor CheckIsAllowedRedecl and stop function definition merging (#4800)
Rename `CheckIsAllowedRedecl` to `DiagnoseIfInvalidRedecl` to try to better document behavior, and clean up comments. This extends the no-merge-if-defined behavior to functions. It was already the case for class/interface, and just added for impl, so if anything functions were now inconsistent. I was kind of tempted to make a helper for it, but I didn't think of a great structure/name to get there: `DiagnoseRedef` isn't always called when it's a redefinition, for example due to `extern` diagnostics, it's hard to combine. Cleans up `is_defined` calls to rely more on `has_definition_started`, removing some code paths that are unused since definitions aren't merged.
This commit is contained in:
@@ -65,13 +65,13 @@ static auto MergeClassRedecl(Context& context, SemIRLoc new_loc,
|
||||
return false;
|
||||
}
|
||||
|
||||
CheckIsAllowedRedecl(
|
||||
DiagnoseIfInvalidRedecl(
|
||||
context, Lex::TokenKind::Class, prev_class.name_id,
|
||||
RedeclInfo(new_class, new_loc, new_is_definition),
|
||||
RedeclInfo(prev_class, prev_loc, prev_class.is_defined()),
|
||||
RedeclInfo(prev_class, prev_loc, prev_class.has_definition_started()),
|
||||
prev_import_ir_id);
|
||||
|
||||
if (new_is_definition && prev_class.is_defined()) {
|
||||
if (new_is_definition && prev_class.has_definition_started()) {
|
||||
// Don't attempt to merge multiple definitions.
|
||||
return false;
|
||||
}
|
||||
@@ -280,11 +280,10 @@ auto HandleParseNode(Context& context, Parse::ClassDefinitionStartId node_id)
|
||||
auto& class_info = context.classes().Get(class_id);
|
||||
|
||||
// Track that this declaration is the definition.
|
||||
if (!class_info.is_defined()) {
|
||||
class_info.definition_id = class_decl_id;
|
||||
class_info.scope_id = context.name_scopes().Add(
|
||||
class_decl_id, SemIR::NameId::Invalid, class_info.parent_scope_id);
|
||||
}
|
||||
CARBON_CHECK(!class_info.has_definition_started());
|
||||
class_info.definition_id = class_decl_id;
|
||||
class_info.scope_id = context.name_scopes().Add(
|
||||
class_decl_id, SemIR::NameId::Invalid, class_info.parent_scope_id);
|
||||
|
||||
// Enter the class scope.
|
||||
context.scope_stack().Push(
|
||||
|
||||
Reference in New Issue
Block a user