Only permit checked downcasts of an existential to a subtype,

not to an arbitrary type that's convertible to the existential.
Arbitrary conversions aren't necessarily reversible.

The specific test case in rdar://16041990 involves a downcast
to String instead of NSString; that's supportable in principle,
but it's at the very least a significant feature, and clearly
there are non-reversible conversions out there.

Swift SVN r14028
This commit is contained in:
John McCall
2014-02-18 02:27:31 +00:00
parent 99ae104980
commit ef4fb36c50

View File

@@ -1288,7 +1288,7 @@ ConstraintSystem::simplifyCheckedCastConstraint(
return SolutionKind::Solved;
case CheckedCastKind::ExistentialToConcrete:
addConstraint(ConstraintKind::Conversion, toType, fromType);
addConstraint(ConstraintKind::Subtype, toType, fromType);
return SolutionKind::Solved;
case CheckedCastKind::Coercion: