@@ -3881,8 +3881,9 @@ static Expr *generateConstraintsFor(ConstraintSystem &cs, Expr *expr,
3881
3881
// / initializes the underlying storage variable.
3882
3882
// / \param wrappedVar The property that has a property wrapper.
3883
3883
// / \returns the type of the property.
3884
- static Type generateWrappedPropertyTypeConstraints (
3885
- ConstraintSystem &cs, Type initializerType, VarDecl *wrappedVar) {
3884
+ static bool generateWrappedPropertyTypeConstraints (
3885
+ ConstraintSystem &cs, Type initializerType, VarDecl *wrappedVar,
3886
+ Type propertyType) {
3886
3887
auto dc = wrappedVar->getInnermostDeclContext ();
3887
3888
3888
3889
Type wrapperType = LValueType::get (initializerType);
@@ -3896,7 +3897,7 @@ static Type generateWrappedPropertyTypeConstraints(
3896
3897
Type rawWrapperType = wrappedVar->getAttachedPropertyWrapperType (i);
3897
3898
auto wrapperInfo = wrappedVar->getAttachedPropertyWrapperTypeInfo (i);
3898
3899
if (rawWrapperType->hasError () || !wrapperInfo)
3899
- return Type () ;
3900
+ return true ;
3900
3901
3901
3902
// The former wrappedValue type must be equal to the current wrapper type
3902
3903
if (wrappedValueType) {
@@ -3914,12 +3915,12 @@ static Type generateWrappedPropertyTypeConstraints(
3914
3915
dc->getParentModule (), wrapperInfo.valueVar );
3915
3916
}
3916
3917
3917
- // Set up an equality constraint to drop the lvalue-ness of the value
3918
- // type we produced.
3919
- auto locator = cs.getConstraintLocator (wrappedVar);
3920
- Type propertyType = cs.createTypeVariable (locator, 0 );
3921
- cs. addConstraint (ConstraintKind::Equal, propertyType, wrappedValueType, locator );
3922
- return propertyType ;
3918
+ // The property type must be equal to the wrapped value type
3919
+ cs. addConstraint (ConstraintKind::Equal, propertyType, wrappedValueType,
3920
+ cs.getConstraintLocator (wrappedVar, LocatorPathElt::ContextualType ()) );
3921
+ cs.setContextualType (wrappedVar, TypeLoc::withoutLoc (wrappedValueType),
3922
+ CTP_WrappedProperty );
3923
+ return false ;
3923
3924
}
3924
3925
3925
3926
// / Generate additional constraints for the pattern of an initialization.
@@ -3936,17 +3937,11 @@ static bool generateInitPatternConstraints(
3936
3937
if (!patternType)
3937
3938
return true ;
3938
3939
3939
- if (auto wrappedVar = target.getInitializationWrappedVar ()) {
3940
- Type propertyType = generateWrappedPropertyTypeConstraints (
3941
- cs, cs.getType (target.getAsExpr ()), wrappedVar);
3942
- if (!propertyType)
3943
- return true ;
3940
+ if (auto wrappedVar = target.getInitializationWrappedVar ())
3941
+ return generateWrappedPropertyTypeConstraints (
3942
+ cs, cs.getType (target.getAsExpr ()), wrappedVar, patternType);
3944
3943
3945
- // Add an equal constraint between the pattern type and the
3946
- // property wrapper's "value" type.
3947
- cs.addConstraint (ConstraintKind::Equal, patternType,
3948
- propertyType, locator, /* isFavored*/ true );
3949
- } else if (!patternType->is <OpaqueTypeArchetypeType>()) {
3944
+ if (!patternType->is <OpaqueTypeArchetypeType>()) {
3950
3945
// Add a conversion constraint between the types.
3951
3946
cs.addConstraint (ConstraintKind::Conversion, cs.getType (target.getAsExpr ()),
3952
3947
patternType, locator, /* isFavored*/ true );
@@ -4190,17 +4185,12 @@ bool ConstraintSystem::generateConstraints(
4190
4185
getConstraintLocator (typeRepr));
4191
4186
setType (typeRepr, backingType);
4192
4187
4193
- auto wrappedValueType =
4194
- generateWrappedPropertyTypeConstraints (*this , backingType, wrappedVar);
4195
- Type propertyType = wrappedVar->getType ();
4196
- if (!wrappedValueType || propertyType->hasError ())
4188
+ auto propertyType = wrappedVar->getType ();
4189
+ if (propertyType->hasError ())
4197
4190
return true ;
4198
4191
4199
- addConstraint (ConstraintKind::Equal, propertyType, wrappedValueType,
4200
- getConstraintLocator (wrappedVar, LocatorPathElt::ContextualType ()));
4201
- setContextualType (wrappedVar, TypeLoc::withoutLoc (wrappedValueType),
4202
- CTP_WrappedProperty);
4203
- return false ;
4192
+ return generateWrappedPropertyTypeConstraints (
4193
+ *this , backingType, wrappedVar, propertyType);
4204
4194
}
4205
4195
}
4206
4196
}
0 commit comments