[Diagnostics] Do more checking before recording force downcast fix

Solver should do more checking upfront before recording
`force downcast` fix, to make sure that it's indeed always
applicable when recorded, otherwise it would be possible
to misdiagnose or omit diagnostics in certain situations.

Resolves: rdar://problem/65254452
This commit is contained in:
Pavel Yaskevich
2020-08-03 16:24:19 -07:00
parent a0426df7a7
commit d89c096af7
3 changed files with 23 additions and 2 deletions

View File

@@ -2968,6 +2968,9 @@ static bool
repairViaBridgingCast(ConstraintSystem &cs, Type fromType, Type toType,
SmallVectorImpl<RestrictionOrFix> &conversionsOrFixes,
ConstraintLocatorBuilder locator) {
if (fromType->hasTypeVariable() || toType->hasTypeVariable())
return false;
auto objectType1 = fromType->getOptionalObjectType();
auto objectType2 = toType->getOptionalObjectType();
@@ -2986,6 +2989,9 @@ repairViaBridgingCast(ConstraintSystem &cs, Type fromType, Type toType,
if (!canBridgeThroughCast(cs, fromType, toType))
return false;
if (!TypeChecker::checkedCastMaySucceed(fromType, toType, cs.DC))
return false;
conversionsOrFixes.push_back(ForceDowncast::create(
cs, fromType, toType, cs.getConstraintLocator(locator)));
return true;