@@ -3535,9 +3535,6 @@ namespace {
3535
3535
return nullptr ;
3536
3536
case CheckedCastKind::Coercion:
3537
3537
case CheckedCastKind::BridgingCoercion: {
3538
- if (SuppressDiagnostics)
3539
- return nullptr ;
3540
-
3541
3538
if (cs.getType (sub)->isEqual (toType)) {
3542
3539
ctx.Diags .diagnose (expr->getLoc (), diag::forced_downcast_noop, toType)
3543
3540
.fixItRemove (SourceRange (
@@ -3551,14 +3548,9 @@ namespace {
3551
3548
" as" );
3552
3549
}
3553
3550
3554
- // Transmute the checked cast into a coercion expression.
3555
- auto *result =
3556
- new (ctx) CoerceExpr (sub, expr->getLoc (), expr->getCastTypeLoc ());
3557
- cs.setType (result, toType);
3558
- cs.setType (result->getCastTypeLoc (), toType);
3559
- unsigned disjunctionChoice =
3560
- (castKind == CheckedCastKind::Coercion ? 0 : 1 );
3561
- return visitCoerceExpr (result, disjunctionChoice);
3551
+ expr->setCastKind (castKind);
3552
+ cs.setType (expr, toType);
3553
+ return expr;
3562
3554
}
3563
3555
3564
3556
// Valid casts.
@@ -3611,37 +3603,18 @@ namespace {
3611
3603
fromType, toType, castContextKind, cs.DC , expr->getLoc (), sub,
3612
3604
expr->getCastTypeLoc ().getSourceRange ());
3613
3605
switch (castKind) {
3614
- / / / Invalid cast.
3606
+ // Invalid cast.
3615
3607
case CheckedCastKind::Unresolved:
3616
3608
expr->setCastKind (CheckedCastKind::ValueCast);
3617
3609
break ;
3618
3610
3619
3611
case CheckedCastKind::Coercion:
3620
3612
case CheckedCastKind::BridgingCoercion: {
3621
- if (SuppressDiagnostics)
3622
- return nullptr ;
3623
-
3624
3613
ctx.Diags .diagnose (expr->getLoc (), diag::conditional_downcast_coercion,
3625
3614
cs.getType (sub), toType);
3626
-
3627
- // Transmute the checked cast into a coercion expression.
3628
- auto *coerce =
3629
- new (ctx) CoerceExpr (sub, expr->getLoc (), expr->getCastTypeLoc ());
3630
- cs.setType (coerce, toType);
3631
- cs.setType (coerce->getCastTypeLoc (), toType);
3632
- unsigned disjunctionChoice =
3633
- (castKind == CheckedCastKind::Coercion ? 0 : 1 );
3634
- Expr *result = visitCoerceExpr (coerce, disjunctionChoice);
3635
- if (!result)
3636
- return nullptr ;
3637
-
3638
- // Wrap the result in an optional. Mark the optional injection as
3639
- // explicit, because the user did in fact write the '?' as part of
3640
- // 'as?', even though it wasn't necessary.
3641
- result =
3642
- new (ctx) InjectIntoOptionalExpr (result, OptionalType::get (toType));
3643
- result->setImplicit (false );
3644
- return cs.cacheType (result);
3615
+ expr->setCastKind (castKind);
3616
+ cs.setType (expr, OptionalType::get (toType));
3617
+ return expr;
3645
3618
}
3646
3619
3647
3620
// Valid casts.
0 commit comments