@@ -4209,26 +4209,35 @@ static Expr *generateConstraintsFor(ConstraintSystem &cs, Expr *expr,
4209
4209
static Type generateWrappedPropertyTypeConstraints (
4210
4210
ConstraintSystem &cs, Type initializerType,
4211
4211
VarDecl *wrappedVar, ConstraintLocator *locator) {
4212
- Type valueType = LValueType::get (initializerType);
4213
4212
auto dc = wrappedVar->getInnermostDeclContext ();
4214
4213
4214
+ Type wrapperType = LValueType::get (initializerType);
4215
+ Type wrappedValueType;
4216
+
4215
4217
for (unsigned i : indices (wrappedVar->getAttachedPropertyWrappers ())) {
4218
+ Type rawWrapperType = wrappedVar->getAttachedPropertyWrapperType (i);
4219
+ if (!rawWrapperType || rawWrapperType->hasError ())
4220
+ return Type ();
4221
+
4222
+ // The former wrappedValue type must be equal to the current wrapper type
4223
+ if (wrappedValueType) {
4224
+ wrapperType = cs.openUnboundGenericTypes (rawWrapperType, locator);
4225
+ cs.addConstraint (ConstraintKind::Equal, wrappedValueType, wrapperType,
4226
+ locator);
4227
+ }
4228
+
4216
4229
auto wrapperInfo = wrappedVar->getAttachedPropertyWrapperTypeInfo (i);
4217
4230
if (!wrapperInfo)
4218
- break ;
4219
-
4220
- locator = cs.getConstraintLocator (locator, ConstraintLocator::Member);
4221
- Type memberType = cs.createTypeVariable (locator, TVO_CanBindToLValue);
4222
- cs.addValueMemberConstraint (
4223
- valueType, wrapperInfo.valueVar ->createNameRef (),
4224
- memberType, dc, FunctionRefKind::Unapplied, { }, locator);
4225
- valueType = memberType;
4231
+ return Type ();
4232
+
4233
+ wrappedValueType = wrapperType->getTypeOfMember (
4234
+ dc->getParentModule (), wrapperInfo.valueVar );
4226
4235
}
4227
4236
4228
4237
// Set up an equality constraint to drop the lvalue-ness of the value
4229
4238
// type we produced.
4230
4239
Type propertyType = cs.createTypeVariable (locator, 0 );
4231
- cs.addConstraint (ConstraintKind::Equal, propertyType, valueType , locator);
4240
+ cs.addConstraint (ConstraintKind::Equal, propertyType, wrappedValueType , locator);
4232
4241
return propertyType;
4233
4242
}
4234
4243
@@ -4245,10 +4254,13 @@ static bool generateInitPatternConstraints(
4245
4254
assert (patternType && " All patterns have a type" );
4246
4255
4247
4256
if (auto wrappedVar = target.getInitializationWrappedVar ()) {
4248
- // Add an equal constraint between the pattern type and the
4249
- // property wrapper's "value" type.
4250
4257
Type propertyType = generateWrappedPropertyTypeConstraints (
4251
4258
cs, cs.getType (target.getAsExpr ()), wrappedVar, locator);
4259
+ if (!propertyType)
4260
+ return true ;
4261
+
4262
+ // Add an equal constraint between the pattern type and the
4263
+ // property wrapper's "value" type.
4252
4264
cs.addConstraint (ConstraintKind::Equal, patternType,
4253
4265
propertyType, locator, /* isFavored*/ true );
4254
4266
} else if (!patternType->is <OpaqueTypeArchetypeType>()) {
0 commit comments