@@ -1021,9 +1021,21 @@ ConstraintSystem::getWrappedPropertyInformation(
1021
1021
// / \param baseType - the type of the base on which this object
1022
1022
// / is being accessed; must be null if and only if this is not
1023
1023
// / a type member
1024
- static bool doesStorageProduceLValue (AbstractStorageDecl *storage,
1025
- Type baseType, DeclContext *useDC,
1026
- const DeclRefExpr *base = nullptr ) {
1024
+ static bool
1025
+ doesStorageProduceLValue (AbstractStorageDecl *storage, Type baseType,
1026
+ DeclContext *useDC,
1027
+ ConstraintLocator *memberLocator = nullptr ) {
1028
+ const DeclRefExpr *base = nullptr ;
1029
+ if (memberLocator) {
1030
+ if (auto *const E = getAsExpr (memberLocator->getAnchor ())) {
1031
+ if (auto *MRE = dyn_cast<MemberRefExpr>(E)) {
1032
+ base = dyn_cast<DeclRefExpr>(MRE->getBase ());
1033
+ } else if (auto *UDE = dyn_cast<UnresolvedDotExpr>(E)) {
1034
+ base = dyn_cast<DeclRefExpr>(UDE->getBase ());
1035
+ }
1036
+ }
1037
+ }
1038
+
1027
1039
// Unsettable storage decls always produce rvalues.
1028
1040
if (!storage->isSettable (useDC, base))
1029
1041
return false ;
@@ -1043,10 +1055,9 @@ static bool doesStorageProduceLValue(AbstractStorageDecl *storage,
1043
1055
!storage->isSetterMutating ());
1044
1056
}
1045
1057
1046
- Type ConstraintSystem::getUnopenedTypeOfReference (VarDecl *value, Type baseType,
1047
- DeclContext *UseDC,
1048
- const DeclRefExpr *base,
1049
- bool wantInterfaceType) {
1058
+ Type ConstraintSystem::getUnopenedTypeOfReference (
1059
+ VarDecl *value, Type baseType, DeclContext *UseDC,
1060
+ ConstraintLocator *memberLocator, bool wantInterfaceType) {
1050
1061
return ConstraintSystem::getUnopenedTypeOfReference (
1051
1062
value, baseType, UseDC,
1052
1063
[&](VarDecl *var) -> Type {
@@ -1059,13 +1070,13 @@ Type ConstraintSystem::getUnopenedTypeOfReference(VarDecl *value, Type baseType,
1059
1070
1060
1071
return wantInterfaceType ? var->getInterfaceType () : var->getType ();
1061
1072
},
1062
- base , wantInterfaceType);
1073
+ memberLocator , wantInterfaceType);
1063
1074
}
1064
1075
1065
1076
Type ConstraintSystem::getUnopenedTypeOfReference (
1066
1077
VarDecl *value, Type baseType, DeclContext *UseDC,
1067
- llvm::function_ref<Type(VarDecl *)> getType, const DeclRefExpr *base,
1068
- bool wantInterfaceType) {
1078
+ llvm::function_ref<Type(VarDecl *)> getType,
1079
+ ConstraintLocator *memberLocator, bool wantInterfaceType) {
1069
1080
Type requestedType =
1070
1081
getType (value)->getWithoutSpecifierType ()->getReferenceStorageReferent ();
1071
1082
@@ -1081,7 +1092,7 @@ Type ConstraintSystem::getUnopenedTypeOfReference(
1081
1092
1082
1093
// Qualify storage declarations with an lvalue when appropriate.
1083
1094
// Otherwise, they yield rvalues (and the access must be a load).
1084
- if (doesStorageProduceLValue (value, baseType, UseDC, base ) &&
1095
+ if (doesStorageProduceLValue (value, baseType, UseDC, memberLocator ) &&
1085
1096
!requestedType->hasError ()) {
1086
1097
return LValueType::get (requestedType);
1087
1098
}
@@ -1566,18 +1577,6 @@ ConstraintSystem::getTypeOfMemberReference(
1566
1577
unsigned numRemovedArgumentLabels = getNumRemovedArgumentLabels (
1567
1578
value, /* isCurriedInstanceReference*/ !hasAppliedSelf, functionRefKind);
1568
1579
1569
- const auto getBaseAsDeclRefExpr = [&] {
1570
- if (auto *E = getAsExpr (locator->getAnchor ())) {
1571
- if (auto *MRE = dyn_cast<MemberRefExpr>(E)) {
1572
- return dyn_cast<DeclRefExpr>(MRE->getBase ());
1573
- } else if (auto *UDE = dyn_cast<UnresolvedDotExpr>(E)) {
1574
- return dyn_cast<DeclRefExpr>(UDE->getBase ());
1575
- }
1576
- }
1577
-
1578
- return (DeclRefExpr *)nullptr ;
1579
- };
1580
-
1581
1580
AnyFunctionType *funcType;
1582
1581
1583
1582
if (isa<AbstractFunctionDecl>(value) ||
@@ -1593,8 +1592,7 @@ ConstraintSystem::getTypeOfMemberReference(
1593
1592
if (auto *subscript = dyn_cast<SubscriptDecl>(value)) {
1594
1593
auto elementTy = subscript->getElementInterfaceType ();
1595
1594
1596
- if (doesStorageProduceLValue (subscript, baseTy, useDC,
1597
- getBaseAsDeclRefExpr ()))
1595
+ if (doesStorageProduceLValue (subscript, baseTy, useDC, locator))
1598
1596
elementTy = LValueType::get (elementTy);
1599
1597
1600
1598
// See ConstraintSystem::resolveOverload() -- optional and dynamic
@@ -1611,7 +1609,7 @@ ConstraintSystem::getTypeOfMemberReference(
1611
1609
refType = FunctionType::get (indices, elementTy);
1612
1610
} else {
1613
1611
refType = getUnopenedTypeOfReference (cast<VarDecl>(value), baseTy, useDC,
1614
- getBaseAsDeclRefExpr () ,
1612
+ locator ,
1615
1613
/* wantInterfaceType=*/ true );
1616
1614
}
1617
1615
0 commit comments