mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 17:13:16 +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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user