@@ -1508,8 +1508,7 @@ ConstraintSystem::getTypeOfMemberReference(
1508
1508
Type baseTy, ValueDecl *value, DeclContext *useDC,
1509
1509
bool isDynamicResult,
1510
1510
FunctionRefKind functionRefKind,
1511
- ConstraintLocatorBuilder locator,
1512
- const DeclRefExpr *base,
1511
+ ConstraintLocator *locator,
1513
1512
OpenedTypeMap *replacementsPtr) {
1514
1513
// Figure out the instance type used for the base.
1515
1514
Type resolvedBaseTy = getFixedTypeRecursive (baseTy, /* wantRValue=*/ true );
@@ -1534,9 +1533,8 @@ ConstraintSystem::getTypeOfMemberReference(
1534
1533
bool isStaticMemberRefOnProtocol = false ;
1535
1534
if (resolvedBaseTy->is <MetatypeType>() && baseObjTy->isExistentialType () &&
1536
1535
value->isStatic ()) {
1537
- if (auto last = locator.last ())
1538
- isStaticMemberRefOnProtocol =
1539
- last->is <LocatorPathElt::UnresolvedMember>();
1536
+ isStaticMemberRefOnProtocol =
1537
+ locator->isLastElement <LocatorPathElt::UnresolvedMember>();
1540
1538
}
1541
1539
1542
1540
if (auto *typeDecl = dyn_cast<TypeDecl>(value)) {
@@ -1568,6 +1566,18 @@ ConstraintSystem::getTypeOfMemberReference(
1568
1566
unsigned numRemovedArgumentLabels = getNumRemovedArgumentLabels (
1569
1567
value, /* isCurriedInstanceReference*/ !hasAppliedSelf, functionRefKind);
1570
1568
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
+
1571
1581
AnyFunctionType *funcType;
1572
1582
1573
1583
if (isa<AbstractFunctionDecl>(value) ||
@@ -1583,7 +1593,8 @@ ConstraintSystem::getTypeOfMemberReference(
1583
1593
if (auto *subscript = dyn_cast<SubscriptDecl>(value)) {
1584
1594
auto elementTy = subscript->getElementInterfaceType ();
1585
1595
1586
- if (doesStorageProduceLValue (subscript, baseTy, useDC, base))
1596
+ if (doesStorageProduceLValue (subscript, baseTy, useDC,
1597
+ getBaseAsDeclRefExpr ()))
1587
1598
elementTy = LValueType::get (elementTy);
1588
1599
1589
1600
// See ConstraintSystem::resolveOverload() -- optional and dynamic
@@ -1599,9 +1610,9 @@ ConstraintSystem::getTypeOfMemberReference(
1599
1610
->castTo <AnyFunctionType>()->getParams ();
1600
1611
refType = FunctionType::get (indices, elementTy);
1601
1612
} else {
1602
- refType =
1603
- getUnopenedTypeOfReference (cast<VarDecl>(value), baseTy, useDC, base ,
1604
- /* wantInterfaceType=*/ true );
1613
+ refType = getUnopenedTypeOfReference (cast<VarDecl>(value), baseTy, useDC,
1614
+ getBaseAsDeclRefExpr () ,
1615
+ /* wantInterfaceType=*/ true );
1605
1616
}
1606
1617
1607
1618
auto selfTy = outerDC->getSelfInterfaceType ();
@@ -1757,7 +1768,7 @@ ConstraintSystem::getTypeOfMemberReference(
1757
1768
// (e.g. "colorLiteralRed:") by stripping all the redundant stuff about
1758
1769
// literals (leaving e.g. "red:").
1759
1770
{
1760
- auto anchor = locator. getAnchor ();
1771
+ auto anchor = locator-> getAnchor ();
1761
1772
if (auto *OLE = getAsExpr<ObjectLiteralExpr>(anchor)) {
1762
1773
auto fnType = type->castTo <FunctionType>();
1763
1774
@@ -2726,28 +2737,11 @@ void ConstraintSystem::resolveOverload(ConstraintLocator *locator,
2726
2737
// Retrieve the type of a reference to the specific declaration choice.
2727
2738
assert (!baseTy->hasTypeParameter ());
2728
2739
2729
- auto getDotBase = [](const Expr *E) -> const DeclRefExpr * {
2730
- if (E == nullptr ) return nullptr ;
2731
- switch (E->getKind ()) {
2732
- case ExprKind::MemberRef: {
2733
- auto Base = cast<MemberRefExpr>(E)->getBase ();
2734
- return dyn_cast<const DeclRefExpr>(Base);
2735
- }
2736
- case ExprKind::UnresolvedDot: {
2737
- auto Base = cast<UnresolvedDotExpr>(E)->getBase ();
2738
- return dyn_cast<const DeclRefExpr>(Base);
2739
- }
2740
- default :
2741
- return nullptr ;
2742
- }
2743
- };
2744
- auto *anchor = locator ? getAsExpr (locator->getAnchor ()) : nullptr ;
2745
- auto base = getDotBase (anchor);
2746
2740
std::tie (openedFullType, refType)
2747
2741
= getTypeOfMemberReference (baseTy, choice.getDecl (), useDC,
2748
2742
(kind == OverloadChoiceKind::DeclViaDynamic),
2749
2743
choice.getFunctionRefKind (),
2750
- locator, base, nullptr );
2744
+ locator, nullptr );
2751
2745
} else {
2752
2746
std::tie (openedFullType, refType)
2753
2747
= getTypeOfReference (choice.getDecl (),
0 commit comments