@@ -3583,9 +3583,6 @@ namespace {
3583
3583
return nullptr ;
3584
3584
case CheckedCastKind::Coercion:
3585
3585
case CheckedCastKind::BridgingCoercion: {
3586
- if (SuppressDiagnostics)
3587
- return nullptr ;
3588
-
3589
3586
if (cs.getType (sub)->isEqual (toType)) {
3590
3587
ctx.Diags .diagnose (expr->getLoc (), diag::forced_downcast_noop, toType)
3591
3588
.fixItRemove (SourceRange (
@@ -3599,14 +3596,9 @@ namespace {
3599
3596
" as" );
3600
3597
}
3601
3598
3602
- // Transmute the checked cast into a coercion expression.
3603
- auto *result =
3604
- new (ctx) CoerceExpr (sub, expr->getLoc (), expr->getCastTypeLoc ());
3605
- cs.setType (result, toType);
3606
- cs.setType (result->getCastTypeLoc (), toType);
3607
- unsigned disjunctionChoice =
3608
- (castKind == CheckedCastKind::Coercion ? 0 : 1 );
3609
- return visitCoerceExpr (result, disjunctionChoice);
3599
+ expr->setCastKind (castKind);
3600
+ cs.setType (expr, toType);
3601
+ return expr;
3610
3602
}
3611
3603
3612
3604
// Valid casts.
@@ -3659,37 +3651,18 @@ namespace {
3659
3651
fromType, toType, castContextKind, cs.DC , expr->getLoc (), sub,
3660
3652
expr->getCastTypeLoc ().getSourceRange ());
3661
3653
switch (castKind) {
3662
- / / / Invalid cast.
3654
+ // Invalid cast.
3663
3655
case CheckedCastKind::Unresolved:
3664
3656
expr->setCastKind (CheckedCastKind::ValueCast);
3665
3657
break ;
3666
3658
3667
3659
case CheckedCastKind::Coercion:
3668
3660
case CheckedCastKind::BridgingCoercion: {
3669
- if (SuppressDiagnostics)
3670
- return nullptr ;
3671
-
3672
3661
ctx.Diags .diagnose (expr->getLoc (), diag::conditional_downcast_coercion,
3673
3662
cs.getType (sub), toType);
3674
-
3675
- // Transmute the checked cast into a coercion expression.
3676
- auto *coerce =
3677
- new (ctx) CoerceExpr (sub, expr->getLoc (), expr->getCastTypeLoc ());
3678
- cs.setType (coerce, toType);
3679
- cs.setType (coerce->getCastTypeLoc (), toType);
3680
- unsigned disjunctionChoice =
3681
- (castKind == CheckedCastKind::Coercion ? 0 : 1 );
3682
- Expr *result = visitCoerceExpr (coerce, disjunctionChoice);
3683
- if (!result)
3684
- return nullptr ;
3685
-
3686
- // Wrap the result in an optional. Mark the optional injection as
3687
- // explicit, because the user did in fact write the '?' as part of
3688
- // 'as?', even though it wasn't necessary.
3689
- result =
3690
- new (ctx) InjectIntoOptionalExpr (result, OptionalType::get (toType));
3691
- result->setImplicit (false );
3692
- return cs.cacheType (result);
3663
+ expr->setCastKind (castKind);
3664
+ cs.setType (expr, OptionalType::get (toType));
3665
+ return expr;
3693
3666
}
3694
3667
3695
3668
// Valid casts.
0 commit comments