[CS] Fix a couple of fixPropertyWrapperFailure crashers

Make sure we query the constraint system for a type if we have a local
property wrapper in a closure to avoid kicking interface type
computation outside the closure, and make sure we map into context if
we need to.
This commit is contained in:
Hamish Knight
2025-10-26 09:55:49 +00:00
parent 3b57a7cd91
commit 260d10f6b8
3 changed files with 17 additions and 5 deletions

View File

@@ -1255,6 +1255,15 @@ static Type getPropertyWrapperTypeFromOverload(
if (!wrapperVar)
return Type();
// First check to see if we have a type for this wrapper variable, which will
// the case for e.g local wrappers in closures.
if (auto ty = cs.getTypeIfAvailable(wrapperVar))
return ty;
// If we don't have a type for the wrapper variable this shouldn't be a
// VarDecl we're solving for.
ASSERT(!cs.hasType(D) && "Should have recorded type for wrapper var");
// For the backing property we need to query the request to ensure it kicks
// type-checking if necessary. Otherwise we can query the interface type.
auto ty = wrapperVar == D->getPropertyWrapperBackingProperty()
@@ -1263,10 +1272,13 @@ static Type getPropertyWrapperTypeFromOverload(
if (!ty)
return Type();
// If this is a for a property, substitute the base type.
if (auto baseType = resolvedOverload.choice.getBaseType())
// If this is a for a property, substitute the base type. Otherwise we have
// a local property wrapper and need to map the resulting type into context.
if (auto baseType = resolvedOverload.choice.getBaseType()) {
ty = baseType->getRValueType()->getTypeOfMember(wrapperVar, ty);
} else {
ty = cs.DC->mapTypeIntoContext(ty);
}
return ty;
}

View File

@@ -1,5 +1,5 @@
// {"kind":"typecheck","signature":"swift::constraints::ConstraintSystem::getClosureType(swift::ClosureExpr const*) const","signatureAssert":"Assertion failed: (result), function getClosureType"}
// RUN: not --crash %target-swift-frontend -typecheck %s
// RUN: not %target-swift-frontend -typecheck %s
@propertyWrapper struct a<b {
wrappedValue: b
}

View File

@@ -1,5 +1,5 @@
// {"kind":"typecheck","signature":"swift::TypeChecker::performTypoCorrection(swift::DeclContext*, swift::DeclRefKind, swift::Type, swift::optionset::OptionSet<swift::NameLookupFlags, unsigned int>, swift::TypoCorrectionResults&, swift::GenericSignature, unsigned int)","signatureAssert":"Assertion failed: (!baseTypeOrNull || !baseTypeOrNull->hasTypeParameter() || genericSig), function performTypoCorrection"}
// RUN: not --crash %target-swift-frontend -typecheck %s
// RUN: not %target-swift-frontend -typecheck %s
enum a<b {
@propertyWrapper class e {wrappedValue:b var projectedValue: a? {
@e var wrappedValue: b wrappedValue.d