@@ -3560,9 +3560,7 @@ static bool generateWrappedPropertyTypeConstraints(
3560
3560
Type propertyType) {
3561
3561
auto dc = wrappedVar->getInnermostDeclContext ();
3562
3562
3563
- Type wrapperType = LValueType::get (initializerType);
3564
3563
Type wrappedValueType;
3565
-
3566
3564
auto wrapperAttributes = wrappedVar->getAttachedPropertyWrappers ();
3567
3565
for (unsigned i : indices (wrapperAttributes)) {
3568
3566
// FIXME: We should somehow pass an OpenUnboundGenericTypeFn to
@@ -3573,16 +3571,20 @@ static bool generateWrappedPropertyTypeConstraints(
3573
3571
if (rawWrapperType->hasError () || !wrapperInfo)
3574
3572
return true ;
3575
3573
3576
- // The former wrappedValue type must be equal to the current wrapper type
3577
- if (wrappedValueType) {
3578
- auto *typeRepr = wrapperAttributes[i]->getTypeRepr ();
3579
- auto *locator =
3580
- cs.getConstraintLocator (typeRepr, LocatorPathElt::ContextualType ());
3581
- wrapperType = cs.replaceInferableTypesWithTypeVars (rawWrapperType,
3582
- locator);
3574
+ auto *typeExpr = wrapperAttributes[i]->getTypeExpr ();
3575
+ auto *locator = cs.getConstraintLocator (typeExpr);
3576
+ auto wrapperType = cs.replaceInferableTypesWithTypeVars (rawWrapperType, locator);
3577
+ cs.setType (typeExpr, wrapperType);
3578
+
3579
+ if (!wrappedValueType) {
3580
+ // Equate the outermost wrapper type to the initializer type.
3581
+ if (initializerType)
3582
+ cs.addConstraint (ConstraintKind::Equal, wrapperType, initializerType, locator);
3583
+ } else {
3584
+ // The former wrappedValue type must be equal to the current wrapper type
3583
3585
cs.addConstraint (ConstraintKind::Equal, wrapperType, wrappedValueType,
3584
- locator);
3585
- cs.setContextualType (typeRepr , TypeLoc::withoutLoc (wrappedValueType),
3586
+ cs. getConstraintLocator ( locator, LocatorPathElt::ContextualType ()) );
3587
+ cs.setContextualType (typeExpr , TypeLoc::withoutLoc (wrappedValueType),
3586
3588
CTP_ComposedPropertyWrapper);
3587
3589
}
3588
3590
@@ -3888,19 +3890,12 @@ bool ConstraintSystem::generateConstraints(
3888
3890
3889
3891
case SolutionApplicationTarget::Kind::uninitializedWrappedVar: {
3890
3892
auto *wrappedVar = target.getAsUninitializedWrappedVar ();
3891
- auto *outermostWrapper = wrappedVar->getAttachedPropertyWrappers ().front ();
3892
- auto *typeExpr = outermostWrapper->getTypeExpr ();
3893
- auto backingType = replaceInferableTypesWithTypeVars (
3894
- outermostWrapper->getType (),getConstraintLocator (typeExpr));
3895
-
3896
- setType (typeExpr, backingType);
3897
-
3898
3893
auto propertyType = getVarType (wrappedVar);
3899
3894
if (propertyType->hasError ())
3900
3895
return true ;
3901
3896
3902
3897
return generateWrappedPropertyTypeConstraints (
3903
- *this , backingType , wrappedVar, propertyType);
3898
+ *this , /* initializerType= */ Type () , wrappedVar, propertyType);
3904
3899
}
3905
3900
}
3906
3901
}
0 commit comments