@@ -34,7 +34,8 @@ static Expr *skipImplicitConversions(Expr *expr) {
3434}
3535
3636// / \brief Find the declaration directly referenced by this expression.
37- static ValueDecl *findReferencedDecl (Expr *expr, DeclNameLoc &loc) {
37+ static std::pair<ValueDecl *, FunctionRefKind>
38+ findReferencedDecl (Expr *expr, DeclNameLoc &loc) {
3839 do {
3940 expr = expr->getSemanticsProvidingExpr ();
4041
@@ -45,10 +46,10 @@ static ValueDecl *findReferencedDecl(Expr *expr, DeclNameLoc &loc) {
4546
4647 if (auto dre = dyn_cast<DeclRefExpr>(expr)) {
4748 loc = dre->getNameLoc ();
48- return dre->getDecl ();
49+ return { dre->getDecl (), dre-> getFunctionRefKind () } ;
4950 }
5051
51- return nullptr ;
52+ return { nullptr , FunctionRefKind::Unapplied } ;
5253 } while (true );
5354}
5455
@@ -1002,12 +1003,11 @@ namespace {
10021003 // The base must have a member of the given name, such that accessing
10031004 // that member through the base returns a value convertible to the type
10041005 // of this expression.
1005- // FIXME: use functionRefKind
10061006 auto baseTy = base->getType ();
10071007 auto tv = CS.createTypeVariable (
10081008 CS.getConstraintLocator (expr, ConstraintLocator::Member),
10091009 TVO_CanBindToLValue);
1010- CS.addValueMemberConstraint (baseTy, name, tv,
1010+ CS.addValueMemberConstraint (baseTy, name, tv, functionRefKind,
10111011 CS.getConstraintLocator (expr, ConstraintLocator::Member));
10121012 return tv;
10131013 }
@@ -1119,11 +1119,12 @@ namespace {
11191119 // UnresolvedSubscriptExpr from SubscriptExpr.
11201120 if (decl) {
11211121 OverloadChoice choice (base->getType (), decl, /* isSpecialized=*/ false ,
1122- FunctionRefKind::SingleApply );
1122+ FunctionRefKind::DoubleApply );
11231123 CS.addBindOverloadConstraint (fnTy, choice, subscriptMemberLocator);
11241124 } else {
11251125 CS.addValueMemberConstraint (baseTy, Context.Id_subscript ,
1126- fnTy, subscriptMemberLocator);
1126+ fnTy, FunctionRefKind::DoubleApply,
1127+ subscriptMemberLocator);
11271128 }
11281129
11291130 // Add the constraint that the index expression's type be convertible
@@ -1208,13 +1209,15 @@ namespace {
12081209 segment->getType (),
12091210 segmentTyV,
12101211 Identifier (),
1212+ FunctionRefKind::Compound,
12111213 locator));
12121214
12131215 DeclName segmentName (C, C.Id_init , { C.Id_stringInterpolationSegment });
12141216 CS.addConstraint (Constraint::create (CS, ConstraintKind::ValueMember,
12151217 tvMeta,
12161218 methodTy,
12171219 segmentName,
1220+ FunctionRefKind::DoubleApply,
12181221 locator));
12191222
12201223 }
@@ -1384,7 +1387,7 @@ namespace {
13841387
13851388 choices.push_back (OverloadChoice (Type (), decls[i],
13861389 expr->isSpecialized (),
1387- /* FIXME: */ FunctionRefKind::DoubleApply ));
1390+ expr-> getFunctionRefKind () ));
13881391 }
13891392
13901393 // If there are no valid overloads, give up.
@@ -1420,6 +1423,10 @@ namespace {
14201423 auto baseLocator = CS.getConstraintLocator (
14211424 expr,
14221425 ConstraintLocator::MemberRefBase);
1426+ FunctionRefKind functionRefKind =
1427+ expr->getArgument () ? FunctionRefKind::DoubleApply
1428+ : FunctionRefKind::Compound;
1429+
14231430 auto memberLocator
14241431 = CS.getConstraintLocator (expr, ConstraintLocator::UnresolvedMember);
14251432 auto baseTy = CS.createTypeVariable (baseLocator, /* options=*/ 0 );
@@ -1434,7 +1441,8 @@ namespace {
14341441 // member, i.e., an enum case or a static variable.
14351442 auto baseMetaTy = MetatypeType::get (baseTy);
14361443 CS.addUnresolvedValueMemberConstraint (baseMetaTy, expr->getName (),
1437- memberTy, memberLocator);
1444+ memberTy, functionRefKind,
1445+ memberLocator);
14381446
14391447 // If there is an argument, apply it.
14401448 if (auto arg = expr->getArgument ()) {
@@ -1494,7 +1502,7 @@ namespace {
14941502 /* options=*/ 0 );
14951503 auto methodTy = FunctionType::get (argsTy, resultTy);
14961504 CS.addValueMemberConstraint (baseTy, expr->getName (),
1497- methodTy,
1505+ methodTy, expr-> getFunctionRefKind (),
14981506 CS.getConstraintLocator (expr, ConstraintLocator::ConstructorMember));
14991507
15001508 // The result of the expression is the partial application of the
@@ -1503,7 +1511,7 @@ namespace {
15031511 }
15041512
15051513 return addMemberRefConstraints (expr, expr->getBase (), expr->getName (),
1506- /* FIXME: */ FunctionRefKind::DoubleApply );
1514+ expr-> getFunctionRefKind () );
15071515 }
15081516
15091517 Type visitUnresolvedSpecializeExpr (UnresolvedSpecializeExpr *expr) {
@@ -2495,7 +2503,9 @@ namespace {
24952503 if (CS.shouldAttemptFixes ()) {
24962504 Constraint *coerceConstraint =
24972505 Constraint::create (CS, ConstraintKind::ExplicitConversion,
2498- fromType, toType, DeclName (), locator);
2506+ fromType, toType, DeclName (),
2507+ FunctionRefKind::Compound,
2508+ locator);
24992509 Constraint *downcastConstraint =
25002510 Constraint::createFixed (CS, ConstraintKind::CheckedCast,
25012511 FixKind::CoerceToCheckedCast, fromType,
@@ -2730,10 +2740,14 @@ namespace {
27302740 // type-checked down to a call; turn it back into an overloaded
27312741 // member reference expression.
27322742 DeclNameLoc memberLoc;
2733- if (auto member = findReferencedDecl (dotCall->getFn (), memberLoc)) {
2743+ auto memberAndFunctionRef = findReferencedDecl (dotCall->getFn (),
2744+ memberLoc);
2745+ if (memberAndFunctionRef.first ) {
27342746 auto base = skipImplicitConversions (dotCall->getArg ());
27352747 return new (TC.Context ) MemberRefExpr (base,
2736- dotCall->getDotLoc (), member, memberLoc,
2748+ dotCall->getDotLoc (),
2749+ memberAndFunctionRef.first ,
2750+ memberLoc,
27372751 expr->isImplicit ());
27382752 }
27392753 }
@@ -2744,10 +2758,13 @@ namespace {
27442758 // actually matter; turn it back into an overloaded member reference
27452759 // expression.
27462760 DeclNameLoc memberLoc;
2747- if (auto member = findReferencedDecl (dotIgnored->getRHS (), memberLoc)) {
2761+ auto memberAndFunctionRef = findReferencedDecl (dotIgnored->getRHS (),
2762+ memberLoc);
2763+ if (memberAndFunctionRef.first ) {
27482764 auto base = skipImplicitConversions (dotIgnored->getLHS ());
27492765 return new (TC.Context ) MemberRefExpr (base,
2750- dotIgnored->getDotLoc (), member,
2766+ dotIgnored->getDotLoc (),
2767+ memberAndFunctionRef.first ,
27512768 memberLoc, expr->isImplicit ());
27522769 }
27532770 }
@@ -3073,9 +3090,9 @@ Type swift::checkMemberType(DeclContext &DC, Type BaseTy,
30733090 TypeVariableOptions::TVO_CanBindToLValue);
30743091 CS.addConstraint (Constraint::createDisjunction (CS, {
30753092 Constraint::create (CS, ConstraintKind::TypeMember, Ty,
3076- TV, DeclName (Id), Loc),
3093+ TV, DeclName (Id), FunctionRefKind::Compound, Loc),
30773094 Constraint::create (CS, ConstraintKind::ValueMember, Ty,
3078- TV, DeclName (Id), Loc)
3095+ TV, DeclName (Id), FunctionRefKind::DoubleApply, Loc)
30793096 }, Loc));
30803097 Ty = TV;
30813098 }
@@ -3172,7 +3189,8 @@ bool swift::isExtensionApplied(DeclContext &DC, Type BaseTy,
31723189 return ;
31733190 }
31743191 // Add constraints accordingly.
3175- CS.addConstraint (Constraint::create (CS, Kind, First, Second, DeclName (), Loc));
3192+ CS.addConstraint (Constraint::create (CS, Kind, First, Second, DeclName (),
3193+ FunctionRefKind::Compound, Loc));
31763194 };
31773195
31783196 // For every requirement, add a constraint.
@@ -3221,6 +3239,7 @@ static bool canSatisfy(Type T1, Type T2, DeclContext &DC, ConstraintKind Kind,
32213239 T2 = T2.transform (Trans);
32223240 }
32233241 CS.addConstraint (Constraint::create (CS, Kind, T1, T2, DeclName (),
3242+ FunctionRefKind::Compound,
32243243 CS.getConstraintLocator (nullptr )));
32253244 SmallVector<Solution, 4 > Solutions;
32263245 return AllowFreeVariables ?
@@ -3252,7 +3271,8 @@ swift::resolveValueMember(DeclContext &DC, Type BaseTy, DeclName Name) {
32523271 }
32533272 ConstraintSystem CS (*TC, &DC, None);
32543273 MemberLookupResult LookupResult = CS.performMemberLookup (
3255- ConstraintKind::ValueMember, Name, BaseTy, nullptr , false );
3274+ ConstraintKind::ValueMember, Name, BaseTy, FunctionRefKind::DoubleApply,
3275+ nullptr , false );
32563276 if (LookupResult.ViableCandidates .empty ())
32573277 return Result;
32583278 ConstraintLocator *Locator = CS.getConstraintLocator (nullptr );
0 commit comments