@@ -3037,7 +3037,9 @@ CheckedCastKind TypeChecker::typeCheckCheckedCast(Type fromType,
3037
3037
Expr *fromExpr,
3038
3038
SourceRange diagToRange) {
3039
3039
// Determine whether we should suppress diagnostics.
3040
- const bool suppressDiagnostics = contextKind == CheckedCastContextKind::None;
3040
+ const bool suppressDiagnostics =
3041
+ contextKind == CheckedCastContextKind::None ||
3042
+ contextKind == CheckedCastContextKind::Coercion;
3041
3043
assert ((suppressDiagnostics || diagLoc.isValid ()) &&
3042
3044
" diagnostics require a valid source location" );
3043
3045
@@ -3133,6 +3135,7 @@ CheckedCastKind TypeChecker::typeCheckCheckedCast(Type fromType,
3133
3135
3134
3136
switch (contextKind) {
3135
3137
case CheckedCastContextKind::None:
3138
+ case CheckedCastContextKind::Coercion:
3136
3139
llvm_unreachable (" suppressing diagnostics" );
3137
3140
3138
3141
case CheckedCastContextKind::ForcedCast: {
@@ -3264,7 +3267,9 @@ CheckedCastKind TypeChecker::typeCheckCheckedCast(Type fromType,
3264
3267
return castKind;
3265
3268
3266
3269
case CheckedCastKind::Unresolved:
3267
- return failed ();
3270
+ if (contextKind == CheckedCastContextKind::Coercion)
3271
+ return failed ();
3272
+ return castKind;
3268
3273
}
3269
3274
llvm_unreachable (" invalid cast type" );
3270
3275
};
@@ -3295,15 +3300,17 @@ CheckedCastKind TypeChecker::typeCheckCheckedCast(Type fromType,
3295
3300
BridgingCoercion);
3296
3301
break ;
3297
3302
3303
+ case CheckedCastKind::Unresolved:
3304
+ if (contextKind == CheckedCastContextKind::Coercion)
3305
+ return failed ();
3306
+ LLVM_FALLTHROUGH;
3307
+
3298
3308
case CheckedCastKind::ArrayDowncast:
3299
3309
case CheckedCastKind::DictionaryDowncast:
3300
3310
case CheckedCastKind::SetDowncast:
3301
3311
case CheckedCastKind::ValueCast:
3302
3312
hasCast = true ;
3303
3313
break ;
3304
-
3305
- case CheckedCastKind::Unresolved:
3306
- return failed ();
3307
3314
}
3308
3315
3309
3316
switch (typeCheckCheckedCast (fromKeyValue->second , toKeyValue->second ,
@@ -3318,15 +3325,17 @@ CheckedCastKind TypeChecker::typeCheckCheckedCast(Type fromType,
3318
3325
BridgingCoercion);
3319
3326
break ;
3320
3327
3328
+ case CheckedCastKind::Unresolved:
3329
+ if (contextKind == CheckedCastContextKind::Coercion)
3330
+ return failed ();
3331
+ LLVM_FALLTHROUGH;
3332
+
3321
3333
case CheckedCastKind::ArrayDowncast:
3322
3334
case CheckedCastKind::DictionaryDowncast:
3323
3335
case CheckedCastKind::SetDowncast:
3324
3336
case CheckedCastKind::ValueCast:
3325
3337
hasCast = true ;
3326
3338
break ;
3327
-
3328
- case CheckedCastKind::Unresolved:
3329
- return failed ();
3330
3339
}
3331
3340
3332
3341
if (hasCast) return CheckedCastKind::DictionaryDowncast;
@@ -3423,6 +3432,7 @@ CheckedCastKind TypeChecker::typeCheckCheckedCast(Type fromType,
3423
3432
case CheckedCastContextKind::EnumElementPattern:
3424
3433
case CheckedCastContextKind::IsExpr:
3425
3434
case CheckedCastContextKind::None:
3435
+ case CheckedCastContextKind::Coercion:
3426
3436
break ;
3427
3437
}
3428
3438
}
0 commit comments