@@ -928,59 +928,82 @@ TypeVariableType *ConstraintSystem::isRepresentativeFor(
928
928
return *member;
929
929
}
930
930
931
- Optional<std::pair<VarDecl *, Type>>
932
- ConstraintSystem::getStorageWrapperInformation (SelectedOverload resolvedOverload) {
931
+ static Optional<std::pair<VarDecl *, Type>>
932
+ getPropertyWrappersInformationFromOverload (
933
+ SelectedOverload resolvedOverload, DeclContext *DC,
934
+ llvm::function_ref<Optional<std::pair<VarDecl *, Type>>(VarDecl *)>
935
+ getInformation) {
933
936
if (resolvedOverload.choice .isDecl ()) {
934
937
if (auto *decl = dyn_cast<VarDecl>(resolvedOverload.choice .getDecl ())) {
935
- if (decl->hasAttachedPropertyWrapper ()) {
936
- if (auto storageWrapper = decl->getPropertyWrapperStorageWrapper ()) {
937
- Type type = storageWrapper->getInterfaceType ();
938
- if (Type baseType = resolvedOverload.choice .getBaseType ()) {
939
- type = baseType->getTypeOfMember (DC->getParentModule (),
940
- storageWrapper, type);
941
- }
942
- return std::make_pair (decl, type);
938
+ if (auto declInformation = getInformation (decl)) {
939
+ Type type;
940
+ VarDecl *memberDecl;
941
+ std::tie (memberDecl, type) = *declInformation;
942
+ if (Type baseType = resolvedOverload.choice .getBaseType ()) {
943
+ type = baseType->getTypeOfMember (DC->getParentModule (), memberDecl,
944
+ type);
943
945
}
946
+ return std::make_pair (decl, type);
944
947
}
945
948
}
946
949
}
947
950
return None;
948
951
}
949
952
953
+ static Optional<std::pair<VarDecl *, Type>>
954
+ getStorageWrapperInformationFromDecl (VarDecl *decl) {
955
+ if (!decl->hasAttachedPropertyWrapper ())
956
+ return None;
957
+
958
+ auto storageWrapper = decl->getPropertyWrapperStorageWrapper ();
959
+ if (!storageWrapper)
960
+ return None;
961
+
962
+ return std::make_pair (storageWrapper, storageWrapper->getInterfaceType ());
963
+ }
964
+
950
965
Optional<std::pair<VarDecl *, Type>>
951
- ConstraintSystem::getPropertyWrapperInformation (SelectedOverload resolvedOverload) {
952
- if (resolvedOverload.choice .isDecl ()) {
953
- if (auto *decl = dyn_cast<VarDecl>(resolvedOverload.choice .getDecl ())) {
954
- if (decl->hasAttachedPropertyWrapper ()) {
955
- auto wrapperTy = decl->getPropertyWrapperBackingPropertyType ();
956
- if (Type baseType = resolvedOverload.choice .getBaseType ()) {
957
- wrapperTy = baseType->getTypeOfMember (DC->getParentModule (),
958
- decl, wrapperTy);
959
- }
960
- return std::make_pair (decl, wrapperTy);
961
- }
962
- }
963
- }
964
- return None;
966
+ ConstraintSystem::getStorageWrapperInformation (
967
+ SelectedOverload resolvedOverload) {
968
+ return getPropertyWrappersInformationFromOverload (
969
+ resolvedOverload, DC,
970
+ [](VarDecl *decl) { return getStorageWrapperInformationFromDecl (decl); });
971
+ }
972
+
973
+ static Optional<std::pair<VarDecl *, Type>>
974
+ getPropertyWrapperInformationFromDecl (VarDecl *decl) {
975
+ if (!decl->hasAttachedPropertyWrapper ())
976
+ return None;
977
+
978
+ return std::make_pair (decl, decl->getPropertyWrapperBackingPropertyType ());
965
979
}
966
980
967
981
Optional<std::pair<VarDecl *, Type>>
968
- ConstraintSystem::getWrappedPropertyInformation (SelectedOverload resolvedOverload) {
969
- if ( resolvedOverload. choice . isDecl () ) {
970
- if ( auto *decl = dyn_cast<VarDecl>(resolvedOverload. choice . getDecl ())) {
971
- if ( auto wrapped = decl-> getOriginalWrappedProperty () ) {
972
- Type type = wrapped-> getInterfaceType ( );
973
- if (Type baseType = resolvedOverload. choice . getBaseType ()) {
974
- type = baseType-> getTypeOfMember (DC-> getParentModule (),
975
- wrapped, type);
976
- }
977
- return std::make_pair (decl, type);
978
- }
979
- }
980
- }
982
+ ConstraintSystem::getPropertyWrapperInformation (
983
+ SelectedOverload resolvedOverload) {
984
+ return getPropertyWrappersInformationFromOverload (
985
+ resolvedOverload, DC, [](VarDecl * decl) {
986
+ return getPropertyWrapperInformationFromDecl (decl );
987
+ });
988
+ }
989
+
990
+ static Optional<std::pair<VarDecl *, Type>>
991
+ getWrappedPropertyInformationFromDecl (VarDecl *decl) {
992
+ if ( auto wrapped = decl-> getOriginalWrappedProperty ())
993
+ return std::make_pair (decl, wrapped-> getInterfaceType ());
994
+
981
995
return None;
982
996
}
983
997
998
+ Optional<std::pair<VarDecl *, Type>>
999
+ ConstraintSystem::getWrappedPropertyInformation (
1000
+ SelectedOverload resolvedOverload) {
1001
+ return getPropertyWrappersInformationFromOverload (
1002
+ resolvedOverload, DC, [](VarDecl *decl) {
1003
+ return getWrappedPropertyInformationFromDecl (decl);
1004
+ });
1005
+ }
1006
+
984
1007
// / Does a var or subscript produce an l-value?
985
1008
// /
986
1009
// / \param baseType - the type of the base on which this object
0 commit comments