Skip to content

Commit f6beec6

Browse files
authored
Merge pull request swiftlang#10849 from xedin/rdar-33190087
[ConstraintSolver] Fix `shrink` to use correct primary expression as a candidate
2 parents 74eca0d + 78aa1e0 commit f6beec6

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

lib/Sema/CSSolver.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -788,8 +788,7 @@ bool ConstraintSystem::Candidate::solve(
788788
};
789789

790790
// Allocate new constraint system for sub-expression.
791-
ConstraintSystem cs(TC, DC,
792-
ConstraintSystemFlags::ReturnAllDiscoveredSolutions);
791+
ConstraintSystem cs(TC, DC, None);
793792

794793
// Cleanup after constraint system generation/solving,
795794
// because it would assign types to expressions, which
@@ -1021,7 +1020,13 @@ void ConstraintSystem::shrink(Expr *expr) {
10211020
}
10221021

10231022
Expr *walkToExprPost(Expr *expr) override {
1024-
if (expr == PrimaryExpr) {
1023+
auto isSrcOfPrimaryAssignment = [&](Expr *expr) -> bool {
1024+
if (auto *AE = dyn_cast<AssignExpr>(PrimaryExpr))
1025+
return expr == AE->getSrc();
1026+
return false;
1027+
};
1028+
1029+
if (expr == PrimaryExpr || isSrcOfPrimaryAssignment(expr)) {
10251030
// If this is primary expression and there are no candidates
10261031
// to be solved, let's not record it, because it's going to be
10271032
// solved regardless.
@@ -1031,14 +1036,14 @@ void ConstraintSystem::shrink(Expr *expr) {
10311036
auto contextualType = CS.getContextualType();
10321037
// If there is a contextual type set for this expression.
10331038
if (!contextualType.isNull()) {
1034-
Candidates.push_back(Candidate(CS, expr, contextualType,
1039+
Candidates.push_back(Candidate(CS, PrimaryExpr, contextualType,
10351040
CS.getContextualTypePurpose()));
10361041
return expr;
10371042
}
10381043

10391044
// Or it's a function application with other candidates present.
10401045
if (isa<ApplyExpr>(expr)) {
1041-
Candidates.push_back(Candidate(CS, expr));
1046+
Candidates.push_back(Candidate(CS, PrimaryExpr));
10421047
return expr;
10431048
}
10441049
}

0 commit comments

Comments
 (0)