Skip to content

Commit c4fee1d

Browse files
committed
[ConstraintSystem] Use new condition element in constraint generation/diagnostics
1 parent 5a12e95 commit c4fee1d

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1918,6 +1918,16 @@ bool ContextualFailure::diagnoseAsError() {
19181918
break;
19191919
}
19201920

1921+
case ConstraintLocator::Condition: {
1922+
// Tailored diagnostics for optional or assignment use
1923+
// in condition expression.
1924+
if (diagnoseConversionToBool())
1925+
return true;
1926+
1927+
diagnostic = diag::cannot_convert_condition_value;
1928+
break;
1929+
}
1930+
19211931
case ConstraintLocator::ContextualType: {
19221932
if (diagnoseConversionToBool())
19231933
return true;

lib/Sema/CSGen.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2578,10 +2578,10 @@ namespace {
25782578
if (!boolDecl)
25792579
return Type();
25802580

2581-
CS.addConstraint(ConstraintKind::Conversion,
2582-
CS.getType(expr->getCondExpr()),
2583-
boolDecl->getDeclaredType(),
2584-
CS.getConstraintLocator(expr->getCondExpr()));
2581+
CS.addConstraint(
2582+
ConstraintKind::Conversion, CS.getType(expr->getCondExpr()),
2583+
boolDecl->getDeclaredType(),
2584+
CS.getConstraintLocator(expr, LocatorPathElt::Condition()));
25852585

25862586
// The branches must be convertible to a common type.
25872587
return CS.addJoinConstraint(CS.getConstraintLocator(expr),

lib/Sema/CSSimplify.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3186,6 +3186,12 @@ bool ConstraintSystem::repairFailures(
31863186
break;
31873187
}
31883188

3189+
case ConstraintLocator::Condition: {
3190+
conversionsOrFixes.push_back(IgnoreContextualType::create(
3191+
*this, lhs, rhs, getConstraintLocator(locator)));
3192+
break;
3193+
}
3194+
31893195
default:
31903196
break;
31913197
}

0 commit comments

Comments
 (0)