[CS] Avoid solver-allocated inputs with typesSatisfyConstraint

Escaping solver-allocated types into a nested allocation arena is
problematic since we can e.g lazily compute the `ContextSubMap` for a
`NominalOrBoundGenericNominalType`, which is then destroyed when we
exit the nested arena. Ensure we don't pass any types with type
variables or placeholders to `typesSatisfyConstraint`.

rdar://152763265
This commit is contained in:
Hamish Knight
2025-06-10 15:44:09 +01:00
parent 3780aba7df
commit cc66fc886f
10 changed files with 57 additions and 19 deletions

View File

@@ -4903,8 +4903,12 @@ static bool
repairViaBridgingCast(ConstraintSystem &cs, Type fromType, Type toType,
SmallVectorImpl<RestrictionOrFix> &conversionsOrFixes,
ConstraintLocatorBuilder locator) {
if (fromType->hasTypeVariable() || toType->hasTypeVariable())
// Don't check if any of the types have type variables or placeholders,
// `typeCheckCheckedCast` doesn't support checking solver-allocated types.
if (fromType->hasTypeVariableOrPlaceholder() ||
toType->hasTypeVariableOrPlaceholder()) {
return false;
}
auto objectType1 = fromType->getOptionalObjectType();
auto objectType2 = toType->getOptionalObjectType();
@@ -9366,10 +9370,12 @@ static ConstraintFix *maybeWarnAboutExtraneousCast(
if (locator.endsWith<LocatorPathElt::GenericArgument>())
return nullptr;
// Both types have to be fixed.
if (fromType->hasTypeVariable() || toType->hasTypeVariable() ||
fromType->hasPlaceholder() || toType->hasPlaceholder())
// Both types have to be resolved, `typeCheckCheckedCast` doesn't support
// checking solver-allocated types.
if (fromType->hasTypeVariableOrPlaceholder() ||
toType->hasTypeVariableOrPlaceholder()) {
return nullptr;
}
SmallVector<LocatorPathElt, 4> path;
auto anchor = locator.getLocatorParts(path);