@@ -3105,7 +3105,7 @@ CheckedCastKind TypeChecker::typeCheckCheckedCast(Type fromType,
3105
3105
}
3106
3106
3107
3107
// In the context of collection element we just return a value cast
3108
- // becasue there may be situation where this can be convertible
3108
+ // because there may be situations where this can be convertible
3109
3109
// at runtime. e.g.
3110
3110
//
3111
3111
// func f(a: [Any], b: [AnyObject]) {
@@ -3568,9 +3568,9 @@ CheckedCastKind TypeChecker::typeCheckCheckedCast(Type fromType,
3568
3568
// non-final class because it's possible that we might have a subclass
3569
3569
// that conforms to the protocol.
3570
3570
//
3571
- // Also, relax the restriction when toType is a stdlib collection type
3571
+ // Also, relax the restriction when toType is a stdlib collection
3572
3572
// (Array, Set, Dictionary) that could have conditional conformances
3573
- // because of custom casting implemented for those types e.g.
3573
+ // because of custom casting mechanism implemented for those types e.g.
3574
3574
//
3575
3575
// func encodable(_ value: Encodable) {
3576
3576
// _ = value as! [String : Encodable]
@@ -3651,8 +3651,10 @@ CheckedCastKind TypeChecker::typeCheckCheckedCast(Type fromType,
3651
3651
3652
3652
// If it is possible to substitute the generic arguments of source type
3653
3653
// with the destination generic archetypes, we are performing what looks
3654
- // like an upcast except it rebinds generic parameters.
3655
- if (toType->isBindableTo (fromType))
3654
+ // like an upcast except it rebinds generic parameters. Or substitute
3655
+ // destination to source generic archetypes, where we are performing
3656
+ // what looks like an downcast except it also rebinds generic parameters.
3657
+ if (toType->isBindableTo (fromType) || fromType->isBindableTo (toType))
3656
3658
return CheckedCastKind::ValueCast;
3657
3659
3658
3660
// Objective-C metaclasses are subclasses of NSObject in the ObjC runtime,
0 commit comments