@@ -777,55 +777,6 @@ namespace {
777
777
778
778
namespace {
779
779
780
- // / Generate constraints to produce the wrapped value type given the property
781
- // / that has an attached property wrapper.
782
- // /
783
- // / \param initializerType The type of the adjusted initializer, which
784
- // / initializes the underlying storage variable.
785
- // / \param wrappedVar The property that has a property wrapper.
786
- // / \returns the type of the property.
787
- bool generateWrappedPropertyTypeConstraints (
788
- ConstraintSystem &cs, Type initializerType, VarDecl *wrappedVar, Type propertyType) {
789
- auto dc = wrappedVar->getInnermostDeclContext ();
790
-
791
- Type wrapperType = LValueType::get (initializerType);
792
- Type wrappedValueType;
793
-
794
- auto wrapperAttributes = wrappedVar->getAttachedPropertyWrappers ();
795
- for (unsigned i : indices (wrapperAttributes)) {
796
- // FIXME: We should somehow pass an OpenUnboundGenericTypeFn to
797
- // AttachedPropertyWrapperTypeRequest::evaluate to open up unbound
798
- // generics on the fly.
799
- Type rawWrapperType = wrappedVar->getAttachedPropertyWrapperType (i);
800
- auto wrapperInfo = wrappedVar->getAttachedPropertyWrapperTypeInfo (i);
801
- if (rawWrapperType->hasError () || !wrapperInfo)
802
- return true ;
803
-
804
- // The former wrappedValue type must be equal to the current wrapper type
805
- if (wrappedValueType) {
806
- auto *typeRepr = wrapperAttributes[i]->getTypeRepr ();
807
- auto *locator =
808
- cs.getConstraintLocator (typeRepr, LocatorPathElt::ContextualType ());
809
- wrapperType = cs.replaceInferableTypesWithTypeVars (rawWrapperType,
810
- locator);
811
- cs.addConstraint (ConstraintKind::Equal, wrapperType, wrappedValueType,
812
- locator);
813
- cs.setContextualType (typeRepr, TypeLoc::withoutLoc (wrappedValueType),
814
- CTP_ComposedPropertyWrapper);
815
- }
816
-
817
- wrappedValueType = wrapperType->getTypeOfMember (
818
- dc->getParentModule (), wrapperInfo.valueVar );
819
- }
820
-
821
- // The property type must be equal to the wrapped value type
822
- cs.addConstraint (ConstraintKind::Equal, propertyType, wrappedValueType,
823
- cs.getConstraintLocator (wrappedVar, LocatorPathElt::ContextualType ()));
824
- cs.setContextualType (wrappedVar, TypeLoc::withoutLoc (wrappedValueType),
825
- CTP_WrappedProperty);
826
- return false ;
827
- }
828
-
829
780
class ConstraintGenerator : public ExprVisitor <ConstraintGenerator, Type> {
830
781
ConstraintSystem &CS;
831
782
DeclContext *CurDC;
@@ -3603,6 +3554,56 @@ static Expr *generateConstraintsFor(ConstraintSystem &cs, Expr *expr,
3603
3554
return result;
3604
3555
}
3605
3556
3557
+ // / Generate constraints to produce the wrapped value type given the property
3558
+ // / that has an attached property wrapper.
3559
+ // /
3560
+ // / \param initializerType The type of the adjusted initializer, which
3561
+ // / initializes the underlying storage variable.
3562
+ // / \param wrappedVar The property that has a property wrapper.
3563
+ // / \returns the type of the property.
3564
+ static bool generateWrappedPropertyTypeConstraints (
3565
+ ConstraintSystem &cs, Type initializerType, VarDecl *wrappedVar,
3566
+ Type propertyType) {
3567
+ auto dc = wrappedVar->getInnermostDeclContext ();
3568
+
3569
+ Type wrapperType = LValueType::get (initializerType);
3570
+ Type wrappedValueType;
3571
+
3572
+ auto wrapperAttributes = wrappedVar->getAttachedPropertyWrappers ();
3573
+ for (unsigned i : indices (wrapperAttributes)) {
3574
+ // FIXME: We should somehow pass an OpenUnboundGenericTypeFn to
3575
+ // AttachedPropertyWrapperTypeRequest::evaluate to open up unbound
3576
+ // generics on the fly.
3577
+ Type rawWrapperType = wrappedVar->getAttachedPropertyWrapperType (i);
3578
+ auto wrapperInfo = wrappedVar->getAttachedPropertyWrapperTypeInfo (i);
3579
+ if (rawWrapperType->hasError () || !wrapperInfo)
3580
+ return true ;
3581
+
3582
+ // The former wrappedValue type must be equal to the current wrapper type
3583
+ if (wrappedValueType) {
3584
+ auto *typeRepr = wrapperAttributes[i]->getTypeRepr ();
3585
+ auto *locator =
3586
+ cs.getConstraintLocator (typeRepr, LocatorPathElt::ContextualType ());
3587
+ wrapperType = cs.replaceInferableTypesWithTypeVars (rawWrapperType,
3588
+ locator);
3589
+ cs.addConstraint (ConstraintKind::Equal, wrapperType, wrappedValueType,
3590
+ locator);
3591
+ cs.setContextualType (typeRepr, TypeLoc::withoutLoc (wrappedValueType),
3592
+ CTP_ComposedPropertyWrapper);
3593
+ }
3594
+
3595
+ wrappedValueType = wrapperType->getTypeOfMember (
3596
+ dc->getParentModule (), wrapperInfo.valueVar );
3597
+ }
3598
+
3599
+ // The property type must be equal to the wrapped value type
3600
+ cs.addConstraint (ConstraintKind::Equal, propertyType, wrappedValueType,
3601
+ cs.getConstraintLocator (wrappedVar, LocatorPathElt::ContextualType ()));
3602
+ cs.setContextualType (wrappedVar, TypeLoc::withoutLoc (wrappedValueType),
3603
+ CTP_WrappedProperty);
3604
+ return false ;
3605
+ }
3606
+
3606
3607
// / Generate additional constraints for the pattern of an initialization.
3607
3608
static bool generateInitPatternConstraints (
3608
3609
ConstraintSystem &cs, SolutionApplicationTarget target, Expr *initializer) {
0 commit comments