@@ -3602,16 +3602,8 @@ static Expr *generateConstraintsFor(ConstraintSystem &cs, Expr *expr,
3602
3602
return result;
3603
3603
}
3604
3604
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) {
3615
3607
auto dc = wrappedVar->getInnermostDeclContext ();
3616
3608
3617
3609
Type wrappedValueType;
@@ -3630,33 +3622,33 @@ static bool generateWrappedPropertyTypeConstraints(
3630
3622
3631
3623
if (!wrappedValueType) {
3632
3624
// Equate the outermost wrapper type to the initializer type.
3633
- auto *locator = cs. getConstraintLocator (typeExpr);
3625
+ auto *locator = getConstraintLocator (typeExpr);
3634
3626
wrapperType =
3635
- cs. replaceInferableTypesWithTypeVars (rawWrapperType, locator);
3627
+ replaceInferableTypesWithTypeVars (rawWrapperType, locator);
3636
3628
if (initializerType)
3637
- cs. addConstraint (ConstraintKind::Equal, wrapperType, initializerType, locator);
3629
+ addConstraint (ConstraintKind::Equal, wrapperType, initializerType, locator);
3638
3630
} else {
3639
3631
// The former wrappedValue type must be equal to the current wrapper type
3640
- auto *locator = cs. getConstraintLocator (
3632
+ auto *locator = getConstraintLocator (
3641
3633
typeExpr, LocatorPathElt::WrappedValue (wrapperType));
3642
3634
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);
3645
3637
}
3646
3638
3647
- cs. setType (typeExpr, wrapperType);
3639
+ setType (typeExpr, wrapperType);
3648
3640
3649
3641
wrappedValueType = wrapperType->getTypeOfMember (
3650
3642
dc->getParentModule (), wrapperInfo.valueVar );
3651
3643
}
3652
3644
3653
3645
// The property type must be equal to the wrapped value type
3654
- cs. addConstraint (
3646
+ addConstraint (
3655
3647
ConstraintKind::Equal, propertyType, wrappedValueType,
3656
- cs. getConstraintLocator (
3648
+ getConstraintLocator (
3657
3649
wrappedVar, LocatorPathElt::ContextualType (CTP_WrappedProperty)));
3658
- cs. setContextualType (wrappedVar, TypeLoc::withoutLoc (wrappedValueType),
3659
- CTP_WrappedProperty);
3650
+ setContextualType (wrappedVar, TypeLoc::withoutLoc (wrappedValueType),
3651
+ CTP_WrappedProperty);
3660
3652
return false ;
3661
3653
}
3662
3654
@@ -3675,8 +3667,8 @@ static bool generateInitPatternConstraints(
3675
3667
return true ;
3676
3668
3677
3669
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);
3680
3672
3681
3673
if (!patternType->is <OpaqueTypeArchetypeType>()) {
3682
3674
// Add a conversion constraint between the types.
@@ -3971,7 +3963,7 @@ bool ConstraintSystem::generateConstraints(
3971
3963
return true ;
3972
3964
3973
3965
return generateWrappedPropertyTypeConstraints (
3974
- * this , /* initializerType=*/ Type (), wrappedVar , propertyType);
3966
+ wrappedVar , /* initializerType=*/ Type (), propertyType);
3975
3967
} else {
3976
3968
auto pattern = target.getAsUninitializedVar ();
3977
3969
auto locator = getConstraintLocator (
@@ -4161,7 +4153,8 @@ ConstraintSystem::applyPropertyWrapperToParameter(
4161
4153
4162
4154
initKind = PropertyWrapperInitKind::ProjectedValue;
4163
4155
} else {
4164
- generateWrappedPropertyTypeConstraints (*this , wrapperType, param, paramType);
4156
+ Type wrappedValueType = computeWrappedValueType (param, wrapperType);
4157
+ addConstraint (matchKind, paramType, wrappedValueType, locator);
4165
4158
initKind = PropertyWrapperInitKind::WrappedValue;
4166
4159
}
4167
4160
0 commit comments