Clarify the logic for invalid impl redeclarations (#4738)

Follow up to #4179, specifically re:
https://github.com/carbon-language/carbon-lang/pull/4719#discussion_r1894364691
.

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
This commit is contained in:
josh11b
2024-12-23 23:05:12 +00:00
committed by GitHub
co-authored by Josh L
parent f8e60a8ec1
commit 1a5107efa4
+9 -5
View File
@@ -326,13 +326,16 @@ static auto BuildImplDecl(Context& context, Parse::AnyImplDeclId node_id,
{.self_id = self_inst_id, .constraint_id = constraint_inst_id}};
// Add the impl declaration.
bool valid_redeclaration = true;
bool invalid_redeclaration = false;
auto lookup_bucket_ref = context.impls().GetOrAddLookupBucket(impl_info);
for (auto prev_impl_id : lookup_bucket_ref) {
if (MergeImplRedecl(context, impl_info, prev_impl_id)) {
valid_redeclaration = IsValidImplRedecl(context, impl_info, prev_impl_id);
if (valid_redeclaration) {
if (IsValidImplRedecl(context, impl_info, prev_impl_id)) {
impl_decl.impl_id = prev_impl_id;
} else {
// IsValidImplRedecl() has issued a diagnostic, avoid generating more
// diagnostics for this declaration.
invalid_redeclaration = true;
}
break;
}
@@ -369,8 +372,9 @@ static auto BuildImplDecl(Context& context, Parse::AnyImplDeclId node_id,
constraint_type_id);
}
// Impl definitions are required in the same file as the declaration.
if (!is_definition && valid_redeclaration) {
// Impl definitions are required in the same file as the declaration. We skip
// this requirement if we've already issued an invalid redeclaration error.
if (!is_definition && !invalid_redeclaration) {
context.definitions_required().push_back(impl_decl_id);
}