@@ -1568,6 +1568,7 @@ ConstraintSystem::matchTupleTypes(TupleType *tuple1, TupleType *tuple2,
1568
1568
case ConstraintKind::OneWayBindParam:
1569
1569
case ConstraintKind::DefaultClosureType:
1570
1570
case ConstraintKind::UnresolvedMemberChainBase:
1571
+ case ConstraintKind::PropertyWrapper:
1571
1572
llvm_unreachable (" Not a conversion" );
1572
1573
}
1573
1574
@@ -1706,6 +1707,7 @@ static bool matchFunctionRepresentations(FunctionType::ExtInfo einfo1,
1706
1707
case ConstraintKind::OneWayBindParam:
1707
1708
case ConstraintKind::DefaultClosureType:
1708
1709
case ConstraintKind::UnresolvedMemberChainBase:
1710
+ case ConstraintKind::PropertyWrapper:
1709
1711
return true ;
1710
1712
}
1711
1713
@@ -2096,6 +2098,7 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
2096
2098
case ConstraintKind::OneWayBindParam:
2097
2099
case ConstraintKind::DefaultClosureType:
2098
2100
case ConstraintKind::UnresolvedMemberChainBase:
2101
+ case ConstraintKind::PropertyWrapper:
2099
2102
llvm_unreachable (" Not a relational constraint" );
2100
2103
}
2101
2104
@@ -5002,6 +5005,7 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
5002
5005
case ConstraintKind::OneWayBindParam:
5003
5006
case ConstraintKind::DefaultClosureType:
5004
5007
case ConstraintKind::UnresolvedMemberChainBase:
5008
+ case ConstraintKind::PropertyWrapper:
5005
5009
llvm_unreachable (" Not a relational constraint" );
5006
5010
}
5007
5011
}
@@ -8104,6 +8108,58 @@ ConstraintSystem::simplifyDefaultClosureTypeConstraint(
8104
8108
return SolutionKind::Solved;
8105
8109
}
8106
8110
8111
+ ConstraintSystem::SolutionKind
8112
+ ConstraintSystem::simplifyPropertyWrapperConstraint (
8113
+ Type wrapperType, Type wrappedValueType, TypeMatchOptions flags,
8114
+ ConstraintLocatorBuilder locator) {
8115
+ wrapperType = getFixedTypeRecursive (wrapperType, flags, /* wantRValue=*/ true );
8116
+ auto *loc = getConstraintLocator (locator);
8117
+
8118
+ if (wrapperType->isTypeVariableOrMember ()) {
8119
+ if (flags.contains (TMF_GenerateConstraints)) {
8120
+ addUnsolvedConstraint (Constraint::create (
8121
+ *this , ConstraintKind::PropertyWrapper, wrapperType, wrappedValueType, loc));
8122
+
8123
+ return SolutionKind::Solved;
8124
+ }
8125
+
8126
+ return SolutionKind::Unsolved;
8127
+ }
8128
+
8129
+ ConstraintFix *fix = nullptr ;
8130
+
8131
+ // The wrapper type must be a property wrapper.
8132
+ auto *nominal = wrapperType->getAnyNominal ();
8133
+ if (!(nominal && nominal->getAttrs ().hasAttribute <PropertyWrapperAttr>())) {
8134
+ if (auto *paramDecl = getAsDecl<ParamDecl>(locator.getAnchor ())) {
8135
+ fix = RemoveProjectedValueArgument::create (*this , wrapperType, paramDecl,
8136
+ getConstraintLocator (paramDecl));
8137
+ } else {
8138
+ return SolutionKind::Error;
8139
+ }
8140
+ }
8141
+
8142
+ auto typeInfo = nominal->getPropertyWrapperTypeInfo ();
8143
+ if (!(typeInfo.projectedValueVar && typeInfo.hasProjectedValueInit )) {
8144
+ if (auto *paramDecl = getAsDecl<ParamDecl>(locator.getAnchor ())) {
8145
+ fix = RemoveProjectedValueArgument::create (*this , wrapperType, paramDecl,
8146
+ getConstraintLocator (paramDecl));
8147
+ }
8148
+ }
8149
+
8150
+ if (fix) {
8151
+ if (!shouldAttemptFixes () || recordFix (fix))
8152
+ return SolutionKind::Error;
8153
+
8154
+ return SolutionKind::Solved;
8155
+ }
8156
+
8157
+ auto resolvedType = wrapperType->getTypeOfMember (DC->getParentModule (), typeInfo.valueVar );
8158
+ addConstraint (ConstraintKind::Equal, wrappedValueType, resolvedType, locator);
8159
+
8160
+ return SolutionKind::Solved;
8161
+ }
8162
+
8107
8163
ConstraintSystem::SolutionKind
8108
8164
ConstraintSystem::simplifyOneWayConstraint (
8109
8165
ConstraintKind kind,
@@ -8272,51 +8328,36 @@ bool ConstraintSystem::resolveClosure(TypeVariableType *typeVar,
8272
8328
}
8273
8329
8274
8330
if (paramDecl->hasAttachedPropertyWrapper ()) {
8275
- bool hasError = false ;
8276
8331
Type backingType;
8332
+ Type wrappedValueType;
8277
8333
8278
8334
if (paramDecl->hasImplicitPropertyWrapper ()) {
8279
8335
backingType = getContextualParamAt (i)->getPlainType ();
8280
-
8281
- // If the contextual type is not a property wrapper, record a fix.
8282
- auto *nominal = backingType->getAnyNominal ();
8283
- if (!(nominal && nominal->getAttrs ().hasAttribute <PropertyWrapperAttr>())) {
8284
- if (!shouldAttemptFixes ())
8285
- return false ;
8286
-
8287
- paramDecl->visitAuxiliaryDecls ([](VarDecl *var) {
8288
- var->setInvalid ();
8289
- });
8290
-
8291
- auto *fix = RemoveProjectedValueArgument::create (*this , backingType, paramDecl,
8292
- getConstraintLocator (paramDecl));
8293
- recordFix (fix);
8294
- hasError = true ;
8295
- }
8336
+ wrappedValueType = createTypeVariable (getConstraintLocator (locator), TVO_CanBindToHole);
8296
8337
} else {
8297
8338
auto *wrapperAttr = paramDecl->getAttachedPropertyWrappers ().front ();
8298
8339
auto wrapperType = paramDecl->getAttachedPropertyWrapperType (0 );
8299
8340
backingType = replaceInferableTypesWithTypeVars (
8300
8341
wrapperType, getConstraintLocator (wrapperAttr->getTypeRepr ()));
8342
+ wrappedValueType = computeWrappedValueType (paramDecl, backingType);
8301
8343
}
8302
8344
8303
- if (!hasError) {
8304
- auto result = applyPropertyWrapperToParameter (backingType, param.getParameterType (),
8305
- paramDecl, paramDecl->getName (),
8306
- ConstraintKind::Equal, locator);
8307
- if (result.isFailure ())
8308
- return false ;
8309
-
8310
- auto *backingVar = paramDecl->getPropertyWrapperBackingProperty ();
8311
- setType (backingVar, backingType);
8345
+ auto *backingVar = paramDecl->getPropertyWrapperBackingProperty ();
8346
+ setType (backingVar, backingType);
8312
8347
8313
- auto *localWrappedVar = paramDecl->getPropertyWrapperWrappedValueVar ();
8314
- setType (localWrappedVar, computeWrappedValueType (paramDecl, backingType) );
8348
+ auto *localWrappedVar = paramDecl->getPropertyWrapperWrappedValueVar ();
8349
+ setType (localWrappedVar, wrappedValueType );
8315
8350
8316
- if (auto *projection = paramDecl->getPropertyWrapperProjectionVar ()) {
8317
- setType (projection, computeProjectedValueType (paramDecl, backingType));
8318
- }
8351
+ if (auto *projection = paramDecl->getPropertyWrapperProjectionVar ()) {
8352
+ setType (projection, computeProjectedValueType (paramDecl, backingType));
8319
8353
}
8354
+
8355
+ auto result = applyPropertyWrapperToParameter (backingType, param.getParameterType (),
8356
+ paramDecl, paramDecl->getName (),
8357
+ ConstraintKind::Equal,
8358
+ getConstraintLocator (closure));
8359
+ if (result.isFailure ())
8360
+ return false ;
8320
8361
}
8321
8362
8322
8363
Type internalType;
@@ -11049,6 +11090,9 @@ ConstraintSystem::addConstraintImpl(ConstraintKind kind, Type first,
11049
11090
case ConstraintKind::Defaultable:
11050
11091
return simplifyDefaultableConstraint (first, second, subflags, locator);
11051
11092
11093
+ case ConstraintKind::PropertyWrapper:
11094
+ return simplifyPropertyWrapperConstraint (first, second, subflags, locator);
11095
+
11052
11096
case ConstraintKind::FunctionInput:
11053
11097
case ConstraintKind::FunctionResult:
11054
11098
return simplifyFunctionComponentConstraint (kind, first, second,
@@ -11563,6 +11607,12 @@ ConstraintSystem::simplifyConstraint(const Constraint &constraint) {
11563
11607
/* flags*/ None,
11564
11608
constraint.getLocator ());
11565
11609
11610
+ case ConstraintKind::PropertyWrapper:
11611
+ return simplifyPropertyWrapperConstraint (constraint.getFirstType (),
11612
+ constraint.getSecondType (),
11613
+ /* flags*/ None,
11614
+ constraint.getLocator ());
11615
+
11566
11616
case ConstraintKind::FunctionInput:
11567
11617
case ConstraintKind::FunctionResult:
11568
11618
return simplifyFunctionComponentConstraint (constraint.getKind (),
0 commit comments