Skip to content

Commit b9ad96a

Browse files
committed
[CS] Add locator version of findSelectedOverloadFor
1 parent a962f02 commit b9ad96a

File tree

3 files changed

+22
-21
lines changed

3 files changed

+22
-21
lines changed

lib/Sema/CSDiag.cpp

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6326,21 +6326,17 @@ void FailureDiagnosis::diagnoseAmbiguity(Expr *E) {
63266326
/// If an UnresolvedDotExpr, SubscriptMember, etc has been resolved by the
63276327
/// constraint system, return the decl that it references.
63286328
ValueDecl *ConstraintSystem::findResolvedMemberRef(ConstraintLocator *locator) {
6329-
auto *resolvedOverloadSets = this->getResolvedOverloadSets();
6330-
if (!resolvedOverloadSets) return nullptr;
6331-
63326329
// Search through the resolvedOverloadSets to see if we have a resolution for
63336330
// this member. This is an O(n) search, but only happens when producing an
63346331
// error diagnostic.
6335-
for (auto resolved = resolvedOverloadSets;
6336-
resolved; resolved = resolved->Previous) {
6337-
if (resolved->Locator != locator) continue;
6338-
6339-
// We only handle the simplest decl binding.
6340-
if (resolved->Choice.getKind() != OverloadChoiceKind::Decl)
6341-
return nullptr;
6342-
return resolved->Choice.getDecl();
6343-
}
6344-
6345-
return nullptr;
6332+
auto *overload = findSelectedOverloadFor(locator);
6333+
if (!overload)
6334+
return nullptr;
6335+
6336+
// We only want to handle the simplest decl binding.
6337+
auto choice = overload->Choice;
6338+
if (choice.getKind() != OverloadChoiceKind::Decl)
6339+
return nullptr;
6340+
6341+
return choice.getDecl();
63466342
}

lib/Sema/CSDiagnostics.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,7 @@ class FailureDiagnostic {
144144
/// by the constraint solver.
145145
ResolvedOverloadSetListItem *
146146
getResolvedOverload(ConstraintLocator *locator) const {
147-
auto resolvedOverload = CS.getResolvedOverloadSets();
148-
while (resolvedOverload) {
149-
if (resolvedOverload->Locator == locator)
150-
return resolvedOverload;
151-
resolvedOverload = resolvedOverload->Previous;
152-
}
153-
return nullptr;
147+
return CS.findSelectedOverloadFor(locator);
154148
}
155149

156150
/// Retrive the constraint locator for the given anchor and

lib/Sema/ConstraintSystem.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,6 +1592,17 @@ class ConstraintSystem {
15921592
return resolvedOverloadSets;
15931593
}
15941594

1595+
ResolvedOverloadSetListItem *
1596+
findSelectedOverloadFor(ConstraintLocator *locator) const {
1597+
auto resolvedOverload = getResolvedOverloadSets();
1598+
while (resolvedOverload) {
1599+
if (resolvedOverload->Locator == locator)
1600+
return resolvedOverload;
1601+
resolvedOverload = resolvedOverload->Previous;
1602+
}
1603+
return nullptr;
1604+
}
1605+
15951606
ResolvedOverloadSetListItem *findSelectedOverloadFor(Expr *expr) const {
15961607
auto resolvedOverload = getResolvedOverloadSets();
15971608
while (resolvedOverload) {

0 commit comments

Comments
 (0)