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:
Jon Ross-Perkins
2025-01-14 21:13:21 +00:00
committed by GitHub
parent 5b70a3ea91
commit d958caaff3
15 changed files with 194 additions and 141 deletions
+9 -5
View File
@@ -88,11 +88,15 @@ static auto MergeFunctionRedecl(Context& context, SemIRLoc new_loc,
return false;
}
CheckIsAllowedRedecl(context, Lex::TokenKind::Fn, prev_function.name_id,
RedeclInfo(new_function, new_loc, new_is_definition),
RedeclInfo(prev_function, prev_function.latest_decl_id(),
prev_function.has_definition_started()),
prev_import_ir_id);
DiagnoseIfInvalidRedecl(
context, Lex::TokenKind::Fn, prev_function.name_id,
RedeclInfo(new_function, new_loc, new_is_definition),
RedeclInfo(prev_function, prev_function.latest_decl_id(),
prev_function.has_definition_started()),
prev_import_ir_id);
if (new_is_definition && prev_function.has_definition_started()) {
return false;
}
if (!prev_function.first_owning_decl_id.is_valid()) {
prev_function.first_owning_decl_id = new_function.first_owning_decl_id;