@@ -3907,8 +3907,9 @@ static Expr *generateConstraintsFor(ConstraintSystem &cs, Expr *expr,
3907
3907
// / initializes the underlying storage variable.
3908
3908
// / \param wrappedVar The property that has a property wrapper.
3909
3909
// / \returns the type of the property.
3910
- static Type generateWrappedPropertyTypeConstraints (
3911
- ConstraintSystem &cs, Type initializerType, VarDecl *wrappedVar) {
3910
+ static bool generateWrappedPropertyTypeConstraints (
3911
+ ConstraintSystem &cs, Type initializerType, VarDecl *wrappedVar,
3912
+ Type propertyType) {
3912
3913
auto dc = wrappedVar->getInnermostDeclContext ();
3913
3914
3914
3915
Type wrapperType = LValueType::get (initializerType);
@@ -3922,7 +3923,7 @@ static Type generateWrappedPropertyTypeConstraints(
3922
3923
Type rawWrapperType = wrappedVar->getAttachedPropertyWrapperType (i);
3923
3924
auto wrapperInfo = wrappedVar->getAttachedPropertyWrapperTypeInfo (i);
3924
3925
if (rawWrapperType->hasError () || !wrapperInfo)
3925
- return Type () ;
3926
+ return true ;
3926
3927
3927
3928
// The former wrappedValue type must be equal to the current wrapper type
3928
3929
if (wrappedValueType) {
@@ -3940,12 +3941,12 @@ static Type generateWrappedPropertyTypeConstraints(
3940
3941
dc->getParentModule (), wrapperInfo.valueVar );
3941
3942
}
3942
3943
3943
- // Set up an equality constraint to drop the lvalue-ness of the value
3944
- // type we produced.
3945
- auto locator = cs.getConstraintLocator (wrappedVar);
3946
- Type propertyType = cs.createTypeVariable (locator, 0 );
3947
- cs. addConstraint (ConstraintKind::Equal, propertyType, wrappedValueType, locator );
3948
- return propertyType ;
3944
+ // The property type must be equal to the wrapped value type
3945
+ cs. addConstraint (ConstraintKind::Equal, propertyType, wrappedValueType,
3946
+ cs.getConstraintLocator (wrappedVar, LocatorPathElt::ContextualType ()) );
3947
+ cs.setContextualType (wrappedVar, TypeLoc::withoutLoc (wrappedValueType),
3948
+ CTP_WrappedProperty );
3949
+ return false ;
3949
3950
}
3950
3951
3951
3952
// / Generate additional constraints for the pattern of an initialization.
@@ -3962,17 +3963,11 @@ static bool generateInitPatternConstraints(
3962
3963
if (!patternType)
3963
3964
return true ;
3964
3965
3965
- if (auto wrappedVar = target.getInitializationWrappedVar ()) {
3966
- Type propertyType = generateWrappedPropertyTypeConstraints (
3967
- cs, cs.getType (target.getAsExpr ()), wrappedVar);
3968
- if (!propertyType)
3969
- return true ;
3966
+ if (auto wrappedVar = target.getInitializationWrappedVar ())
3967
+ return generateWrappedPropertyTypeConstraints (
3968
+ cs, cs.getType (target.getAsExpr ()), wrappedVar, patternType);
3970
3969
3971
- // Add an equal constraint between the pattern type and the
3972
- // property wrapper's "value" type.
3973
- cs.addConstraint (ConstraintKind::Equal, patternType,
3974
- propertyType, locator, /* isFavored*/ true );
3975
- } else if (!patternType->is <OpaqueTypeArchetypeType>()) {
3970
+ if (!patternType->is <OpaqueTypeArchetypeType>()) {
3976
3971
// Add a conversion constraint between the types.
3977
3972
cs.addConstraint (ConstraintKind::Conversion, cs.getType (target.getAsExpr ()),
3978
3973
patternType, locator, /* isFavored*/ true );
@@ -4216,17 +4211,12 @@ bool ConstraintSystem::generateConstraints(
4216
4211
getConstraintLocator (typeRepr));
4217
4212
setType (typeRepr, backingType);
4218
4213
4219
- auto wrappedValueType =
4220
- generateWrappedPropertyTypeConstraints (*this , backingType, wrappedVar);
4221
- Type propertyType = wrappedVar->getType ();
4222
- if (!wrappedValueType || propertyType->hasError ())
4214
+ auto propertyType = wrappedVar->getType ();
4215
+ if (propertyType->hasError ())
4223
4216
return true ;
4224
4217
4225
- addConstraint (ConstraintKind::Equal, propertyType, wrappedValueType,
4226
- getConstraintLocator (wrappedVar, LocatorPathElt::ContextualType ()));
4227
- setContextualType (wrappedVar, TypeLoc::withoutLoc (wrappedValueType),
4228
- CTP_WrappedProperty);
4229
- return false ;
4218
+ return generateWrappedPropertyTypeConstraints (
4219
+ *this , backingType, wrappedVar, propertyType);
4230
4220
}
4231
4221
}
4232
4222
}
0 commit comments