Skip to content

Commit

Permalink
Repeat lookupIdentifier as non-called if no methods found
Browse files Browse the repository at this point in the history
Signed-off-by: Anna Rift <anna.rift@hpe.com>
  • Loading branch information
riftEmber committed Sep 17, 2024
1 parent 3796c37 commit 9768d57
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
4 changes: 3 additions & 1 deletion frontend/lib/resolution/InitResolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -832,8 +832,10 @@ ID InitResolver::solveNameConflictByIgnoringField(const MatchingIdsWithName& vec
}

bool InitResolver::handleResolvingFieldAccess(const Identifier* node) {
bool resolvingCalledIdent = initResolver_.nearestCalledExpression() == node;
auto parenlessInfo = Resolver::ParenlessOverloadInfo();
auto ids = initResolver_.lookupIdentifier(node, parenlessInfo);
auto ids =
initResolver_.lookupIdentifier(node, resolvingCalledIdent, parenlessInfo);

// Handle and exit early if there were no ambiguities.
if (ids.numIds() == 1) {
Expand Down
23 changes: 20 additions & 3 deletions frontend/lib/resolution/Resolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2723,6 +2723,7 @@ void Resolver::issueAmbiguityErrorIfNeeded(const Identifier* ident,

MatchingIdsWithName Resolver::lookupIdentifier(
const Identifier* ident,
bool resolvingCalledIdent,
ParenlessOverloadInfo& outParenlessOverloadInfo) {
CHPL_ASSERT(scopeStack.size() > 0);
const Scope* scope = scopeStack.back();
Expand All @@ -2736,7 +2737,6 @@ MatchingIdsWithName Resolver::lookupIdentifier(
IdAndFlags::createForBuiltinVar());
}

bool resolvingCalledIdent = nearestCalledExpression() == ident;
LookupConfig config = IDENTIFIER_LOOKUP_CONFIG;
if (!resolvingCalledIdent) config |= LOOKUP_INNERMOST;

Expand Down Expand Up @@ -2992,10 +2992,27 @@ void Resolver::resolveIdentifier(const Identifier* ident) {
}

// lookupIdentifier reports any errors that are needed
bool resolvingCalledIdent = nearestCalledExpression() == ident;
auto parenlessInfo = ParenlessOverloadInfo();
auto ids = lookupIdentifier(ident, parenlessInfo);
auto ids = lookupIdentifier(ident, resolvingCalledIdent, parenlessInfo);

// If we looked up a called identifier and got no method results,
// repeat lookup for the identifier as though it wasn't called, to support
// implicit 'this' calls.
if (resolvingCalledIdent && !ids.isEmpty()) {
bool anyMethod = false;
for (auto idIt = ids.begin(); idIt != ids.end(); ++idIt) {
if (idIt.curIdAndFlags().isMethod()) {
anyMethod = true;
break;
}
}
if (!anyMethod) {
ids = lookupIdentifier(ident, /* resolvingCalledIdent */ false,
parenlessInfo);
}
}

bool resolvingCalledIdent = nearestCalledExpression() == ident;
// TODO: these errors should be enabled for scope resolution
// but for now, they are off, as a temporary measure to enable
// the production compiler handle these cases. To enable this,
Expand Down
1 change: 1 addition & 0 deletions frontend/lib/resolution/Resolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ struct Resolver {

MatchingIdsWithName
lookupIdentifier(const uast::Identifier* ident,
bool resolvingCalledIdent,
ParenlessOverloadInfo& outParenlessOverloadInfo);


Expand Down

0 comments on commit 9768d57

Please sign in to comment.