@@ -3879,35 +3879,38 @@ static Expr *generateConstraintsFor(ConstraintSystem &cs, Expr *expr,
3879
3879
// / \param wrappedVar The property that has a property wrapper.
3880
3880
// / \returns the type of the property.
3881
3881
static Type generateWrappedPropertyTypeConstraints (
3882
- ConstraintSystem &cs, Type initializerType,
3883
- VarDecl *wrappedVar, ConstraintLocator *locator) {
3882
+ ConstraintSystem &cs, Type initializerType, VarDecl *wrappedVar) {
3884
3883
auto dc = wrappedVar->getInnermostDeclContext ();
3885
3884
3886
3885
Type wrapperType = LValueType::get (initializerType);
3887
3886
Type wrappedValueType;
3888
3887
3889
- for (unsigned i : indices (wrappedVar->getAttachedPropertyWrappers ())) {
3888
+ auto wrapperAttributes = wrappedVar->getAttachedPropertyWrappers ();
3889
+ for (unsigned i : indices (wrapperAttributes)) {
3890
3890
Type rawWrapperType = wrappedVar->getAttachedPropertyWrapperType (i);
3891
- if (!rawWrapperType || rawWrapperType->hasError ())
3891
+ auto wrapperInfo = wrappedVar->getAttachedPropertyWrapperTypeInfo (i);
3892
+ if (rawWrapperType->hasError () || !wrapperInfo)
3892
3893
return Type ();
3893
3894
3894
3895
// The former wrappedValue type must be equal to the current wrapper type
3895
3896
if (wrappedValueType) {
3897
+ auto *typeRepr = wrapperAttributes[i]->getTypeRepr ();
3898
+ auto *locator =
3899
+ cs.getConstraintLocator (typeRepr, LocatorPathElt::ContextualType ());
3896
3900
wrapperType = cs.openUnboundGenericTypes (rawWrapperType, locator);
3897
- cs.addConstraint (ConstraintKind::Equal, wrappedValueType, wrapperType ,
3901
+ cs.addConstraint (ConstraintKind::Equal, wrapperType, wrappedValueType ,
3898
3902
locator);
3903
+ cs.setContextualType (typeRepr, TypeLoc::withoutLoc (wrappedValueType),
3904
+ CTP_ComposedPropertyWrapper);
3899
3905
}
3900
3906
3901
- auto wrapperInfo = wrappedVar->getAttachedPropertyWrapperTypeInfo (i);
3902
- if (!wrapperInfo)
3903
- return Type ();
3904
-
3905
3907
wrappedValueType = wrapperType->getTypeOfMember (
3906
3908
dc->getParentModule (), wrapperInfo.valueVar );
3907
3909
}
3908
3910
3909
3911
// Set up an equality constraint to drop the lvalue-ness of the value
3910
3912
// type we produced.
3913
+ auto locator = cs.getConstraintLocator (wrappedVar);
3911
3914
Type propertyType = cs.createTypeVariable (locator, 0 );
3912
3915
cs.addConstraint (ConstraintKind::Equal, propertyType, wrappedValueType, locator);
3913
3916
return propertyType;
@@ -3929,7 +3932,7 @@ static bool generateInitPatternConstraints(
3929
3932
3930
3933
if (auto wrappedVar = target.getInitializationWrappedVar ()) {
3931
3934
Type propertyType = generateWrappedPropertyTypeConstraints (
3932
- cs, cs.getType (target.getAsExpr ()), wrappedVar, locator );
3935
+ cs, cs.getType (target.getAsExpr ()), wrappedVar);
3933
3936
if (!propertyType)
3934
3937
return true ;
3935
3938
@@ -4172,6 +4175,27 @@ bool ConstraintSystem::generateConstraints(
4172
4175
4173
4176
return hadError;
4174
4177
}
4178
+
4179
+ case SolutionApplicationTarget::Kind::uninitializedWrappedVar: {
4180
+ auto *wrappedVar = target.getAsUninitializedWrappedVar ();
4181
+ auto *outermostWrapper = wrappedVar->getAttachedPropertyWrappers ().front ();
4182
+ auto *typeRepr = outermostWrapper->getTypeRepr ();
4183
+ auto backingType = openUnboundGenericTypes (outermostWrapper->getType (),
4184
+ getConstraintLocator (typeRepr));
4185
+ setType (typeRepr, backingType);
4186
+
4187
+ auto wrappedValueType =
4188
+ generateWrappedPropertyTypeConstraints (*this , backingType, wrappedVar);
4189
+ Type propertyType = wrappedVar->getType ();
4190
+ if (!wrappedValueType || propertyType->hasError ())
4191
+ return true ;
4192
+
4193
+ addConstraint (ConstraintKind::Equal, propertyType, wrappedValueType,
4194
+ getConstraintLocator (wrappedVar, LocatorPathElt::ContextualType ()));
4195
+ setContextualType (wrappedVar, TypeLoc::withoutLoc (wrappedValueType),
4196
+ CTP_WrappedProperty);
4197
+ return false ;
4198
+ }
4175
4199
}
4176
4200
}
4177
4201
0 commit comments