Skip to content

Commit 6f2af1f

Browse files
committed
[Diagnostics] Replace getChoiceFor with getCalleeOverloadChoiceIfAvailable
New name is more consistent with existing `getOverloadChoiceIfAvailable` and allows us to clean up a couple of places where `getCalleeLocator` was used directly before.
1 parent 6f83c08 commit 6f2af1f

File tree

2 files changed

+27
-29
lines changed

2 files changed

+27
-29
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,6 @@ Expr *FailureDiagnostic::getBaseExprFor(Expr *anchor) const {
126126
return nullptr;
127127
}
128128

129-
Optional<SelectedOverload>
130-
FailureDiagnostic::getChoiceFor(ConstraintLocator *locator) const {
131-
return getOverloadChoiceIfAvailable(S.getCalleeLocator(locator));
132-
}
133-
134129
Type FailureDiagnostic::restoreGenericParameters(
135130
Type type,
136131
llvm::function_ref<void(GenericTypeParamType *, Type)> substitution) {
@@ -227,7 +222,7 @@ ValueDecl *RequirementFailure::getDeclRef() const {
227222
return getAffectedDeclFromType(
228223
getContextualType(getLocator()->getAnchor()));
229224

230-
if (auto overload = getChoiceFor(getLocator())) {
225+
if (auto overload = getCalleeOverloadChoiceIfAvailable(getLocator())) {
231226
// If there is a declaration associated with this
232227
// failure e.g. an overload choice of the call
233228
// expression, let's see whether failure is
@@ -757,7 +752,7 @@ bool LabelingFailure::diagnoseAsNote() {
757752
return "(" + str + ")";
758753
};
759754

760-
auto selectedOverload = getChoiceFor(getLocator());
755+
auto selectedOverload = getCalleeOverloadChoiceIfAvailable(getLocator());
761756
if (!selectedOverload)
762757
return false;
763758

@@ -1311,7 +1306,7 @@ bool RValueTreatedAsLValueFailure::diagnoseAsError() {
13111306
}
13121307

13131308
bool RValueTreatedAsLValueFailure::diagnoseAsNote() {
1314-
auto overload = getChoiceFor(getLocator());
1309+
auto overload = getCalleeOverloadChoiceIfAvailable(getLocator());
13151310
if (!(overload && overload->choice.isDecl()))
13161311
return false;
13171312

@@ -2003,8 +1998,8 @@ bool ContextualFailure::diagnoseAsError() {
20031998
case ConstraintLocator::RValueAdjustment: {
20041999
auto &cs = getConstraintSystem();
20052000

2006-
auto overload = getChoiceFor(
2007-
cs.getConstraintLocator(anchor, ConstraintLocator::UnresolvedMember));
2001+
auto overload = getOverloadChoiceIfAvailable(
2002+
getConstraintLocator(anchor, ConstraintLocator::UnresolvedMember));
20082003
if (!(overload && overload->choice.isDecl()))
20092004
return false;
20102005

@@ -2067,7 +2062,7 @@ bool ContextualFailure::diagnoseAsError() {
20672062
}
20682063

20692064
bool ContextualFailure::diagnoseAsNote() {
2070-
auto overload = getChoiceFor(getLocator());
2065+
auto overload = getCalleeOverloadChoiceIfAvailable(getLocator());
20712066
if (!(overload && overload->choice.isDecl()))
20722067
return false;
20732068

@@ -3495,7 +3490,7 @@ bool AllowTypeOrInstanceMemberFailure::diagnoseAsError() {
34953490
};
34963491

34973492
auto *baseLoc = cs.getConstraintLocator(ctorRef->getBase());
3498-
if (auto selection = getChoiceFor(baseLoc)) {
3493+
if (auto selection = getCalleeOverloadChoiceIfAvailable(baseLoc)) {
34993494
OverloadChoice choice = selection->choice;
35003495
if (choice.isDecl() && isMutable(choice.getDecl()) &&
35013496
!isCallArgument(initCall) &&
@@ -3906,7 +3901,7 @@ bool MissingArgumentsFailure::diagnoseAsError() {
39063901

39073902
diag.flush();
39083903

3909-
if (auto selectedOverload = getChoiceFor(locator)) {
3904+
if (auto selectedOverload = getCalleeOverloadChoiceIfAvailable(locator)) {
39103905
if (auto *decl = selectedOverload->choice.getDeclOrNull()) {
39113906
emitDiagnostic(decl, diag::decl_declared_here, decl->getFullName());
39123907
}
@@ -3917,7 +3912,7 @@ bool MissingArgumentsFailure::diagnoseAsError() {
39173912

39183913
bool MissingArgumentsFailure::diagnoseAsNote() {
39193914
auto *locator = getLocator();
3920-
if (auto overload = getChoiceFor(locator)) {
3915+
if (auto overload = getCalleeOverloadChoiceIfAvailable(locator)) {
39213916
auto *fn = resolveType(overload->openedType)->getAs<AnyFunctionType>();
39223917
auto loc = overload->choice.getDecl()->getLoc();
39233918
if (loc.isInvalid())
@@ -4038,7 +4033,8 @@ bool MissingArgumentsFailure::diagnoseSingleMissingArgument() const {
40384033
.fixItInsert(insertLoc, insertText.str());
40394034
}
40404035

4041-
if (auto selectedOverload = getChoiceFor(getLocator())) {
4036+
if (auto selectedOverload =
4037+
getCalleeOverloadChoiceIfAvailable(getLocator())) {
40424038
if (auto *decl = selectedOverload->choice.getDeclOrNull()) {
40434039
emitDiagnostic(decl, diag::decl_declared_here, decl->getFullName());
40444040
}
@@ -4158,7 +4154,7 @@ bool MissingArgumentsFailure::diagnoseInvalidTupleDestructuring() const {
41584154
if (!(argExpr && getType(argExpr)->getRValueType()->is<TupleType>()))
41594155
return false;
41604156

4161-
auto selectedOverload = getChoiceFor(locator);
4157+
auto selectedOverload = getCalleeOverloadChoiceIfAvailable(locator);
41624158
if (!selectedOverload)
41634159
return false;
41644160

@@ -4586,7 +4582,7 @@ bool ExtraneousArgumentsFailure::diagnoseAsError() {
45864582

45874583
emitDiagnostic(anchor->getLoc(), diag::extra_arguments_in_call, OS.str());
45884584

4589-
if (auto overload = getChoiceFor(getLocator())) {
4585+
if (auto overload = getCalleeOverloadChoiceIfAvailable(getLocator())) {
45904586
if (auto *decl = overload->choice.getDeclOrNull()) {
45914587
emitDiagnostic(decl, diag::decl_declared_here, decl->getFullName());
45924588
}
@@ -4596,7 +4592,7 @@ bool ExtraneousArgumentsFailure::diagnoseAsError() {
45964592
}
45974593

45984594
bool ExtraneousArgumentsFailure::diagnoseAsNote() {
4599-
auto overload = getChoiceFor(getLocator());
4595+
auto overload = getCalleeOverloadChoiceIfAvailable(getLocator());
46004596
if (!(overload && overload->choice.isDecl()))
46014597
return false;
46024598

@@ -5234,7 +5230,7 @@ bool MutatingMemberRefOnImmutableBase::diagnoseAsError() {
52345230
}
52355231

52365232
bool InvalidTupleSplatWithSingleParameterFailure::diagnoseAsError() {
5237-
auto selectedOverload = getChoiceFor(getLocator());
5233+
auto selectedOverload = getCalleeOverloadChoiceIfAvailable(getLocator());
52385234
if (!selectedOverload || !selectedOverload->choice.isDecl())
52395235
return false;
52405236

@@ -5699,7 +5695,7 @@ bool ExpandArrayIntoVarargsFailure::diagnoseAsError() {
56995695
}
57005696

57015697
bool ExpandArrayIntoVarargsFailure::diagnoseAsNote() {
5702-
auto overload = getChoiceFor(getLocator());
5698+
auto overload = getCalleeOverloadChoiceIfAvailable(getLocator());
57035699
auto anchor = getAnchor();
57045700
if (!overload || !anchor)
57055701
return false;
@@ -5733,7 +5729,7 @@ bool ExtraneousCallFailure::diagnoseAsError() {
57335729
}
57345730
};
57355731

5736-
if (auto overload = getChoiceFor(cs.getCalleeLocator(locator))) {
5732+
if (auto overload = getCalleeOverloadChoiceIfAvailable(locator)) {
57375733
if (auto *decl = overload->choice.getDeclOrNull()) {
57385734
if (auto *enumCase = dyn_cast<EnumElementDecl>(decl)) {
57395735
auto diagnostic = emitDiagnostic(
@@ -5766,13 +5762,12 @@ bool ExtraneousCallFailure::diagnoseAsError() {
57665762

57675763
bool InvalidUseOfTrailingClosure::diagnoseAsError() {
57685764
auto *anchor = getAnchor();
5769-
auto &cs = getConstraintSystem();
57705765

57715766
emitDiagnostic(anchor->getLoc(), diag::trailing_closure_bad_param,
57725767
getToType())
57735768
.highlight(anchor->getSourceRange());
57745769

5775-
if (auto overload = getChoiceFor(cs.getCalleeLocator(getLocator()))) {
5770+
if (auto overload = getCalleeOverloadChoiceIfAvailable(getLocator())) {
57765771
if (auto *decl = overload->choice.getDeclOrNull()) {
57775772
emitDiagnostic(decl, diag::decl_declared_here, decl->getFullName());
57785773
}
@@ -6025,9 +6020,9 @@ bool AssignmentTypeMismatchFailure::diagnoseAsError() {
60256020

60266021
bool AssignmentTypeMismatchFailure::diagnoseAsNote() {
60276022
auto *anchor = getAnchor();
6028-
auto &cs = getConstraintSystem();
60296023

6030-
if (auto overload = getChoiceFor(cs.getConstraintLocator(anchor))) {
6024+
if (auto overload =
6025+
getCalleeOverloadChoiceIfAvailable(getConstraintLocator(anchor))) {
60316026
if (auto *decl = overload->choice.getDeclOrNull()) {
60326027
emitDiagnostic(decl,
60336028
diag::cannot_convert_candidate_result_to_contextual_type,

lib/Sema/CSDiagnostics.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,13 @@ class FailureDiagnostic {
160160
return S.getOverloadChoiceIfAvailable(locator);
161161
}
162162

163+
/// Retrieve overload choice resolved for a callee for the anchor
164+
/// of a given locator.
165+
Optional<SelectedOverload>
166+
getCalleeOverloadChoiceIfAvailable(ConstraintLocator *locator) const {
167+
return getOverloadChoiceIfAvailable(S.getCalleeLocator(locator));
168+
}
169+
163170
ConstraintLocator *
164171
getConstraintLocator(Expr *anchor,
165172
ConstraintLocator::PathElement element) const {
@@ -192,10 +199,6 @@ class FailureDiagnostic {
192199
/// the argument list cannot be found, returns \c nullptr.
193200
Expr *getArgumentListExprFor(ConstraintLocator *locator) const;
194201

195-
/// \returns The overload choice made by the constraint system for the callee
196-
/// of a given locator's anchor, or \c None if no such choice can be found.
197-
Optional<SelectedOverload> getChoiceFor(ConstraintLocator *) const;
198-
199202
/// \returns A new type with all of the type variables associated with
200203
/// generic parameters substituted back into being generic parameter type.
201204
Type restoreGenericParameters(

0 commit comments

Comments
 (0)