<rdar://problem/19671476> Offer as -> as! changes in all nested contexts

When generating constraints for an 'as' expression, consider the
possibility that the code is supposed to be 'as!' instead of 'as'. Emit
the appropriate fixit if that branch of the disjunction is chosen by the
constraint solver.

This is a more comprehensive fix for <rdar://problem/19499340> than the
one in r24815.

Swift SVN r24872
This commit is contained in:
Chris Willmore
2015-01-31 00:55:53 +00:00
parent acfb0c3d15
commit ab86515fb2
6 changed files with 97 additions and 76 deletions

View File

@@ -1922,9 +1922,23 @@ namespace {
auto locator = CS.getConstraintLocator(expr,
ConstraintLocator::CheckedCastOperand);
// The source type can be explicitly converted to the destination type.
CS.addConstraint(ConstraintKind::ExplicitConversion, fromType, toType,
locator);
if (CS.shouldAttemptFixes()) {
Constraint *coerceConstraint =
Constraint::create(CS, ConstraintKind::ExplicitConversion,
fromType, toType, DeclName(), locator);
Constraint *downcastConstraint =
Constraint::create(CS, ConstraintKind::CheckedCast, fromType, toType,
DeclName(), locator);
coerceConstraint->setFavored();
auto constraints = { coerceConstraint, downcastConstraint };
CS.addConstraint(Constraint::createDisjunction(CS, constraints,
locator,
RememberChoice));
} else {
// The source type can be explicitly converted to the destination type.
CS.addConstraint(ConstraintKind::ExplicitConversion, fromType, toType,
locator);
}
return toType;
}