@@ -3572,9 +3572,7 @@ static bool generateWrappedPropertyTypeConstraints(
3572
3572
Type propertyType) {
3573
3573
auto dc = wrappedVar->getInnermostDeclContext ();
3574
3574
3575
- Type wrapperType = LValueType::get (initializerType);
3576
3575
Type wrappedValueType;
3577
-
3578
3576
auto wrapperAttributes = wrappedVar->getAttachedPropertyWrappers ();
3579
3577
for (unsigned i : indices (wrapperAttributes)) {
3580
3578
// FIXME: We should somehow pass an OpenUnboundGenericTypeFn to
@@ -3585,16 +3583,20 @@ static bool generateWrappedPropertyTypeConstraints(
3585
3583
if (rawWrapperType->hasError () || !wrapperInfo)
3586
3584
return true ;
3587
3585
3588
- // The former wrappedValue type must be equal to the current wrapper type
3589
- if (wrappedValueType) {
3590
- auto *typeRepr = wrapperAttributes[i]->getTypeRepr ();
3591
- auto *locator =
3592
- cs.getConstraintLocator (typeRepr, LocatorPathElt::ContextualType ());
3593
- wrapperType = cs.replaceInferableTypesWithTypeVars (rawWrapperType,
3594
- locator);
3586
+ auto *typeExpr = wrapperAttributes[i]->getTypeExpr ();
3587
+ auto *locator = cs.getConstraintLocator (typeExpr);
3588
+ auto wrapperType = cs.replaceInferableTypesWithTypeVars (rawWrapperType, locator);
3589
+ cs.setType (typeExpr, wrapperType);
3590
+
3591
+ if (!wrappedValueType) {
3592
+ // Equate the outermost wrapper type to the initializer type.
3593
+ if (initializerType)
3594
+ cs.addConstraint (ConstraintKind::Equal, wrapperType, initializerType, locator);
3595
+ } else {
3596
+ // The former wrappedValue type must be equal to the current wrapper type
3595
3597
cs.addConstraint (ConstraintKind::Equal, wrapperType, wrappedValueType,
3596
- locator);
3597
- cs.setContextualType (typeRepr , TypeLoc::withoutLoc (wrappedValueType),
3598
+ cs. getConstraintLocator ( locator, LocatorPathElt::ContextualType ()) );
3599
+ cs.setContextualType (typeExpr , TypeLoc::withoutLoc (wrappedValueType),
3598
3600
CTP_ComposedPropertyWrapper);
3599
3601
}
3600
3602
@@ -3900,19 +3902,12 @@ bool ConstraintSystem::generateConstraints(
3900
3902
3901
3903
case SolutionApplicationTarget::Kind::uninitializedWrappedVar: {
3902
3904
auto *wrappedVar = target.getAsUninitializedWrappedVar ();
3903
- auto *outermostWrapper = wrappedVar->getAttachedPropertyWrappers ().front ();
3904
- auto *typeExpr = outermostWrapper->getTypeExpr ();
3905
- auto backingType = replaceInferableTypesWithTypeVars (
3906
- outermostWrapper->getType (),getConstraintLocator (typeExpr));
3907
-
3908
- setType (typeExpr, backingType);
3909
-
3910
3905
auto propertyType = getVarType (wrappedVar);
3911
3906
if (propertyType->hasError ())
3912
3907
return true ;
3913
3908
3914
3909
return generateWrappedPropertyTypeConstraints (
3915
- *this , backingType , wrappedVar, propertyType);
3910
+ *this , /* initializerType= */ Type () , wrappedVar, propertyType);
3916
3911
}
3917
3912
}
3918
3913
}
0 commit comments