When merging functions, detect uses of imports prior to a redecl. (#3836)

LookupNameInDecl is only called from DeclNameStack, but I'm adding
mark_imports_used there because it feels more consistent. Not sure if we
want a better API boundary. I admit I'm also suspicious of its call to
LookupInCurrentScope but maybe it's okay due to how imports work.

I was choosing to print multiple diagnostics when a declaration is
previously used _and_ doesn't match because I think the "previously
used" is more important, but the "doesn't match" may give an additional
hint about why it didn't work.

The merge.h utility function is because I think we can follow a similar
model for identifying errors with other declarations: classes,
interfaces, etc.
This commit is contained in:
Jon Ross-Perkins
2024-04-02 17:44:55 +00:00
committed by GitHub
parent f8c8861e5f
commit dffe4a36de
14 changed files with 471 additions and 96 deletions
+2 -1
View File
@@ -168,7 +168,8 @@ auto DeclNameStack::ApplyNameQualifierTo(NameContext& name_context,
if (TryResolveQualifier(name_context, loc_id)) {
// For identifier nodes, we need to perform a lookup on the identifier.
auto resolved_inst_id = context_->LookupNameInDecl(
name_context.loc_id, name_id, name_context.target_scope_id);
name_context.loc_id, name_id, name_context.target_scope_id,
/*mark_imports_used=*/false);
if (!resolved_inst_id.is_valid()) {
// Invalid indicates an unresolved name. Store it and return.
name_context.state = NameContext::State::Unresolved;