@@ -3602,16 +3602,8 @@ static Expr *generateConstraintsFor(ConstraintSystem &cs, Expr *expr,
36023602 return result;
36033603}
36043604
3605- // / Generate constraints to produce the wrapped value type given the property
3606- // / that has an attached property wrapper.
3607- // /
3608- // / \param initializerType The type of the adjusted initializer, which
3609- // / initializes the underlying storage variable.
3610- // / \param wrappedVar The property that has a property wrapper.
3611- // / \returns the type of the property.
3612- static bool generateWrappedPropertyTypeConstraints (
3613- ConstraintSystem &cs, Type initializerType, VarDecl *wrappedVar,
3614- Type propertyType) {
3605+ bool ConstraintSystem::generateWrappedPropertyTypeConstraints (
3606+ VarDecl *wrappedVar, Type initializerType, Type propertyType) {
36153607 auto dc = wrappedVar->getInnermostDeclContext ();
36163608
36173609 Type wrappedValueType;
@@ -3630,33 +3622,33 @@ static bool generateWrappedPropertyTypeConstraints(
36303622
36313623 if (!wrappedValueType) {
36323624 // Equate the outermost wrapper type to the initializer type.
3633- auto *locator = cs. getConstraintLocator (typeExpr);
3625+ auto *locator = getConstraintLocator (typeExpr);
36343626 wrapperType =
3635- cs. replaceInferableTypesWithTypeVars (rawWrapperType, locator);
3627+ replaceInferableTypesWithTypeVars (rawWrapperType, locator);
36363628 if (initializerType)
3637- cs. addConstraint (ConstraintKind::Equal, wrapperType, initializerType, locator);
3629+ addConstraint (ConstraintKind::Equal, wrapperType, initializerType, locator);
36383630 } else {
36393631 // The former wrappedValue type must be equal to the current wrapper type
3640- auto *locator = cs. getConstraintLocator (
3632+ auto *locator = getConstraintLocator (
36413633 typeExpr, LocatorPathElt::WrappedValue (wrapperType));
36423634 wrapperType =
3643- cs. replaceInferableTypesWithTypeVars (rawWrapperType, locator);
3644- cs. addConstraint (ConstraintKind::Equal, wrapperType, wrappedValueType, locator);
3635+ replaceInferableTypesWithTypeVars (rawWrapperType, locator);
3636+ addConstraint (ConstraintKind::Equal, wrapperType, wrappedValueType, locator);
36453637 }
36463638
3647- cs. setType (typeExpr, wrapperType);
3639+ setType (typeExpr, wrapperType);
36483640
36493641 wrappedValueType = wrapperType->getTypeOfMember (
36503642 dc->getParentModule (), wrapperInfo.valueVar );
36513643 }
36523644
36533645 // The property type must be equal to the wrapped value type
3654- cs. addConstraint (
3646+ addConstraint (
36553647 ConstraintKind::Equal, propertyType, wrappedValueType,
3656- cs. getConstraintLocator (
3648+ getConstraintLocator (
36573649 wrappedVar, LocatorPathElt::ContextualType (CTP_WrappedProperty)));
3658- cs. setContextualType (wrappedVar, TypeLoc::withoutLoc (wrappedValueType),
3659- CTP_WrappedProperty);
3650+ setContextualType (wrappedVar, TypeLoc::withoutLoc (wrappedValueType),
3651+ CTP_WrappedProperty);
36603652 return false ;
36613653}
36623654
@@ -3675,8 +3667,8 @@ static bool generateInitPatternConstraints(
36753667 return true ;
36763668
36773669 if (auto wrappedVar = target.getInitializationWrappedVar ())
3678- return generateWrappedPropertyTypeConstraints (
3679- cs , cs.getType (target.getAsExpr ()), wrappedVar , patternType);
3670+ return cs. generateWrappedPropertyTypeConstraints (
3671+ wrappedVar , cs.getType (target.getAsExpr ()), patternType);
36803672
36813673 if (!patternType->is <OpaqueTypeArchetypeType>()) {
36823674 // Add a conversion constraint between the types.
@@ -3971,7 +3963,7 @@ bool ConstraintSystem::generateConstraints(
39713963 return true ;
39723964
39733965 return generateWrappedPropertyTypeConstraints (
3974- * this , /* initializerType=*/ Type (), wrappedVar , propertyType);
3966+ wrappedVar , /* initializerType=*/ Type (), propertyType);
39753967 } else {
39763968 auto pattern = target.getAsUninitializedVar ();
39773969 auto locator = getConstraintLocator (
@@ -4161,7 +4153,8 @@ ConstraintSystem::applyPropertyWrapperToParameter(
41614153
41624154 initKind = PropertyWrapperInitKind::ProjectedValue;
41634155 } else {
4164- generateWrappedPropertyTypeConstraints (*this , wrapperType, param, paramType);
4156+ Type wrappedValueType = computeWrappedValueType (param, wrapperType);
4157+ addConstraint (matchKind, paramType, wrappedValueType, locator);
41654158 initKind = PropertyWrapperInitKind::WrappedValue;
41664159 }
41674160
0 commit comments