Skip to content

Commit 8ad51b2

Browse files
committed
Sema: Get constraint locator for TupleExpr inside ApplyExpr branch
Additionally has some other minor cleanup.
1 parent 743d8fb commit 8ad51b2

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,18 @@ Optional<SelectedOverload> FailureDiagnostic::getChoiceFor(Expr *expr) {
106106
auto &cs = getConstraintSystem();
107107
ConstraintLocator *locator = nullptr;
108108

109-
if (auto *call = dyn_cast<CallExpr>(expr)) {
110-
auto *fnExpr = call->getFn();
111-
return getChoiceFor(fnExpr);
109+
if (auto *AE = dyn_cast<ApplyExpr>(expr)) {
110+
if (auto *TE = dyn_cast<TypeExpr>(AE->getFn())) {
111+
locator = cs.getConstraintLocator(AE,
112+
{ConstraintLocator::ApplyFunction,
113+
ConstraintLocator::ConstructorMember},
114+
/*summaryFlags=*/0);
115+
}
116+
return getChoiceFor(AE->getFn());
112117
} else if (auto *UDE = dyn_cast<UnresolvedDotExpr>(expr)) {
113118
locator = cs.getConstraintLocator(UDE, ConstraintLocator::Member);
114119
} else if (auto *UME = dyn_cast<UnresolvedMemberExpr>(expr)) {
115120
locator = cs.getConstraintLocator(UME, ConstraintLocator::UnresolvedMember);
116-
} else if (auto *TE = dyn_cast<TypeExpr>(expr)) {
117-
locator = cs.getConstraintLocator(call,
118-
{ConstraintLocator::ApplyFunction,
119-
ConstraintLocator::ConstructorMember},
120-
/*summaryFlags=*/0);
121121
} else if (auto *SE = dyn_cast<SubscriptExpr>(expr)) {
122122
locator = cs.getConstraintLocator(SE, ConstraintLocator::SubscriptMember);
123123
} else {
@@ -2077,8 +2077,8 @@ bool AllowTypeOrInstanceMemberFailure::diagnoseAsError() {
20772077
auto argExpr = cs.getParentExpr(expr);
20782078
if (!argExpr)
20792079
return false;
2080-
auto possibleCallExpr = cs.getParentExpr(expr);
2081-
return possibleCallExpr && isa<CallExpr>(possibleCallExpr);
2080+
auto possibleApplyExpr = cs.getParentExpr(expr);
2081+
return possibleApplyExpr && isa<ApplyExpr>(possibleApplyExpr);
20822082
};
20832083

20842084
auto *initCall = cs.getParentExpr(cs.getParentExpr(ctorRef));
@@ -2092,7 +2092,7 @@ bool AllowTypeOrInstanceMemberFailure::diagnoseAsError() {
20922092

20932093
auto selection = getChoiceFor(ctorRef->getBase());
20942094
if (selection) {
2095-
OverloadChoice choice = selection.getValue().choice;
2095+
OverloadChoice choice = selection->choice;
20962096
if (choice.isDecl() && isMutable(choice.getDecl()) &&
20972097
!isCallArgument(initCall) &&
20982098
cs.getContextualTypePurpose() == CTP_Unused) {

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2646,6 +2646,8 @@ bool TypeChecker::typeCheckBinding(Pattern *&pattern, Expr *&initializer,
26462646
auto contextualPurpose = CTP_Unused;
26472647
TypeCheckExprOptions flags = TypeCheckExprFlags::ConvertTypeIsOnlyAHint;
26482648

2649+
// Set the contextual purpose even if the pattern doesn't have a type so
2650+
// if there's an error we can use that information to inform diagnostics.
26492651
contextualPurpose = CTP_Initialization;
26502652

26512653
if (pattern->hasType()) {

0 commit comments

Comments
 (0)