Skip to content

[ConstraintSolver] Fix shrink to use correct primary expression as a candidate #10849

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 10, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions lib/Sema/CSSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -788,8 +788,7 @@ bool ConstraintSystem::Candidate::solve(
};

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

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

Expr *walkToExprPost(Expr *expr) override {
if (expr == PrimaryExpr) {
auto isSrcOfPrimaryAssignment = [&](Expr *expr) -> bool {
if (auto *AE = dyn_cast<AssignExpr>(PrimaryExpr))
return expr == AE->getSrc();
return false;
};

if (expr == PrimaryExpr || isSrcOfPrimaryAssignment(expr)) {
// If this is primary expression and there are no candidates
// to be solved, let's not record it, because it's going to be
// solved regardless.
Expand All @@ -1031,14 +1036,14 @@ void ConstraintSystem::shrink(Expr *expr) {
auto contextualType = CS.getContextualType();
// If there is a contextual type set for this expression.
if (!contextualType.isNull()) {
Candidates.push_back(Candidate(CS, expr, contextualType,
Candidates.push_back(Candidate(CS, PrimaryExpr, contextualType,
CS.getContextualTypePurpose()));
return expr;
}

// Or it's a function application with other candidates present.
if (isa<ApplyExpr>(expr)) {
Candidates.push_back(Candidate(CS, expr));
Candidates.push_back(Candidate(CS, PrimaryExpr));
return expr;
}
}
Expand Down