mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
<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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user