Skip to content

Commit 2e500ef

Browse files
committed
[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.
1 parent 69510b3 commit 2e500ef

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

lib/Sema/ConstraintSystem.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,6 +1255,15 @@ static Type getPropertyWrapperTypeFromOverload(
12551255
if (!wrapperVar)
12561256
return Type();
12571257

1258+
// First check to see if we have a type for this wrapper variable, which will
1259+
// the case for e.g local wrappers in closures.
1260+
if (auto ty = cs.getTypeIfAvailable(wrapperVar))
1261+
return ty;
1262+
1263+
// If we don't have a type for the wrapper variable this shouldn't be a
1264+
// VarDecl we're solving for.
1265+
ASSERT(!cs.hasType(D) && "Should have recorded type for wrapper var");
1266+
12581267
// For the backing property we need to query the request to ensure it kicks
12591268
// type-checking if necessary. Otherwise we can query the interface type.
12601269
auto ty = wrapperVar == D->getPropertyWrapperBackingProperty()
@@ -1263,10 +1272,13 @@ static Type getPropertyWrapperTypeFromOverload(
12631272
if (!ty)
12641273
return Type();
12651274

1266-
// If this is a for a property, substitute the base type.
1267-
if (auto baseType = resolvedOverload.choice.getBaseType())
1275+
// If this is a for a property, substitute the base type. Otherwise we have
1276+
// a local property wrapper and need to map the resulting type into context.
1277+
if (auto baseType = resolvedOverload.choice.getBaseType()) {
12681278
ty = baseType->getRValueType()->getTypeOfMember(wrapperVar, ty);
1269-
1279+
} else {
1280+
ty = cs.DC->mapTypeIntoContext(ty);
1281+
}
12701282
return ty;
12711283
}
12721284

validation-test/compiler_crashers/ConstraintSystem-getClosureType-36e4ea.swift renamed to validation-test/compiler_crashers_fixed/ConstraintSystem-getClosureType-36e4ea.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// {"kind":"typecheck","signature":"swift::constraints::ConstraintSystem::getClosureType(swift::ClosureExpr const*) const","signatureAssert":"Assertion failed: (result), function getClosureType"}
2-
// RUN: not --crash %target-swift-frontend -typecheck %s
2+
// RUN: not %target-swift-frontend -typecheck %s
33
@propertyWrapper struct a<b {
44
wrappedValue: b
55
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// {"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"}
2-
// RUN: not --crash %target-swift-frontend -typecheck %s
2+
// RUN: not %target-swift-frontend -typecheck %s
33
enum a<b {
44
@propertyWrapper class e {wrappedValue:b var projectedValue: a? {
55
@e var wrappedValue: b wrappedValue.d

0 commit comments

Comments
 (0)