@@ -3879,35 +3879,38 @@ static Expr *generateConstraintsFor(ConstraintSystem &cs, Expr *expr,
38793879// / \param wrappedVar The property that has a property wrapper.
38803880// / \returns the type of the property.
38813881static Type generateWrappedPropertyTypeConstraints (
3882- ConstraintSystem &cs, Type initializerType,
3883- VarDecl *wrappedVar, ConstraintLocator *locator) {
3882+ ConstraintSystem &cs, Type initializerType, VarDecl *wrappedVar) {
38843883 auto dc = wrappedVar->getInnermostDeclContext ();
38853884
38863885 Type wrapperType = LValueType::get (initializerType);
38873886 Type wrappedValueType;
38883887
3889- for (unsigned i : indices (wrappedVar->getAttachedPropertyWrappers ())) {
3888+ auto wrapperAttributes = wrappedVar->getAttachedPropertyWrappers ();
3889+ for (unsigned i : indices (wrapperAttributes)) {
38903890 Type rawWrapperType = wrappedVar->getAttachedPropertyWrapperType (i);
3891- if (!rawWrapperType || rawWrapperType->hasError ())
3891+ auto wrapperInfo = wrappedVar->getAttachedPropertyWrapperTypeInfo (i);
3892+ if (rawWrapperType->hasError () || !wrapperInfo)
38923893 return Type ();
38933894
38943895 // The former wrappedValue type must be equal to the current wrapper type
38953896 if (wrappedValueType) {
3897+ auto *typeRepr = wrapperAttributes[i]->getTypeRepr ();
3898+ auto *locator =
3899+ cs.getConstraintLocator (typeRepr, LocatorPathElt::ContextualType ());
38963900 wrapperType = cs.openUnboundGenericTypes (rawWrapperType, locator);
3897- cs.addConstraint (ConstraintKind::Equal, wrappedValueType, wrapperType ,
3901+ cs.addConstraint (ConstraintKind::Equal, wrapperType, wrappedValueType ,
38983902 locator);
3903+ cs.setContextualType (typeRepr, TypeLoc::withoutLoc (wrappedValueType),
3904+ CTP_ComposedPropertyWrapper);
38993905 }
39003906
3901- auto wrapperInfo = wrappedVar->getAttachedPropertyWrapperTypeInfo (i);
3902- if (!wrapperInfo)
3903- return Type ();
3904-
39053907 wrappedValueType = wrapperType->getTypeOfMember (
39063908 dc->getParentModule (), wrapperInfo.valueVar );
39073909 }
39083910
39093911 // Set up an equality constraint to drop the lvalue-ness of the value
39103912 // type we produced.
3913+ auto locator = cs.getConstraintLocator (wrappedVar);
39113914 Type propertyType = cs.createTypeVariable (locator, 0 );
39123915 cs.addConstraint (ConstraintKind::Equal, propertyType, wrappedValueType, locator);
39133916 return propertyType;
@@ -3929,7 +3932,7 @@ static bool generateInitPatternConstraints(
39293932
39303933 if (auto wrappedVar = target.getInitializationWrappedVar ()) {
39313934 Type propertyType = generateWrappedPropertyTypeConstraints (
3932- cs, cs.getType (target.getAsExpr ()), wrappedVar, locator );
3935+ cs, cs.getType (target.getAsExpr ()), wrappedVar);
39333936 if (!propertyType)
39343937 return true ;
39353938
@@ -4172,6 +4175,27 @@ bool ConstraintSystem::generateConstraints(
41724175
41734176 return hadError;
41744177 }
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+ }
41754199 }
41764200}
41774201
0 commit comments