@@ -34,7 +34,8 @@ static Expr *skipImplicitConversions(Expr *expr) {
34
34
}
35
35
36
36
// / \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) {
38
39
do {
39
40
expr = expr->getSemanticsProvidingExpr ();
40
41
@@ -45,10 +46,10 @@ static ValueDecl *findReferencedDecl(Expr *expr, DeclNameLoc &loc) {
45
46
46
47
if (auto dre = dyn_cast<DeclRefExpr>(expr)) {
47
48
loc = dre->getNameLoc ();
48
- return dre->getDecl ();
49
+ return { dre->getDecl (), dre-> getFunctionRefKind () } ;
49
50
}
50
51
51
- return nullptr ;
52
+ return { nullptr , FunctionRefKind::Unapplied } ;
52
53
} while (true );
53
54
}
54
55
@@ -1002,12 +1003,11 @@ namespace {
1002
1003
// The base must have a member of the given name, such that accessing
1003
1004
// that member through the base returns a value convertible to the type
1004
1005
// of this expression.
1005
- // FIXME: use functionRefKind
1006
1006
auto baseTy = base->getType ();
1007
1007
auto tv = CS.createTypeVariable (
1008
1008
CS.getConstraintLocator (expr, ConstraintLocator::Member),
1009
1009
TVO_CanBindToLValue);
1010
- CS.addValueMemberConstraint (baseTy, name, tv,
1010
+ CS.addValueMemberConstraint (baseTy, name, tv, functionRefKind,
1011
1011
CS.getConstraintLocator (expr, ConstraintLocator::Member));
1012
1012
return tv;
1013
1013
}
@@ -1119,11 +1119,12 @@ namespace {
1119
1119
// UnresolvedSubscriptExpr from SubscriptExpr.
1120
1120
if (decl) {
1121
1121
OverloadChoice choice (base->getType (), decl, /* isSpecialized=*/ false ,
1122
- FunctionRefKind::SingleApply );
1122
+ FunctionRefKind::DoubleApply );
1123
1123
CS.addBindOverloadConstraint (fnTy, choice, subscriptMemberLocator);
1124
1124
} else {
1125
1125
CS.addValueMemberConstraint (baseTy, Context.Id_subscript ,
1126
- fnTy, subscriptMemberLocator);
1126
+ fnTy, FunctionRefKind::DoubleApply,
1127
+ subscriptMemberLocator);
1127
1128
}
1128
1129
1129
1130
// Add the constraint that the index expression's type be convertible
@@ -1208,13 +1209,15 @@ namespace {
1208
1209
segment->getType (),
1209
1210
segmentTyV,
1210
1211
Identifier (),
1212
+ FunctionRefKind::Compound,
1211
1213
locator));
1212
1214
1213
1215
DeclName segmentName (C, C.Id_init , { C.Id_stringInterpolationSegment });
1214
1216
CS.addConstraint (Constraint::create (CS, ConstraintKind::ValueMember,
1215
1217
tvMeta,
1216
1218
methodTy,
1217
1219
segmentName,
1220
+ FunctionRefKind::DoubleApply,
1218
1221
locator));
1219
1222
1220
1223
}
@@ -1384,7 +1387,7 @@ namespace {
1384
1387
1385
1388
choices.push_back (OverloadChoice (Type (), decls[i],
1386
1389
expr->isSpecialized (),
1387
- /* FIXME: */ FunctionRefKind::DoubleApply ));
1390
+ expr-> getFunctionRefKind () ));
1388
1391
}
1389
1392
1390
1393
// If there are no valid overloads, give up.
@@ -1420,6 +1423,10 @@ namespace {
1420
1423
auto baseLocator = CS.getConstraintLocator (
1421
1424
expr,
1422
1425
ConstraintLocator::MemberRefBase);
1426
+ FunctionRefKind functionRefKind =
1427
+ expr->getArgument () ? FunctionRefKind::DoubleApply
1428
+ : FunctionRefKind::Compound;
1429
+
1423
1430
auto memberLocator
1424
1431
= CS.getConstraintLocator (expr, ConstraintLocator::UnresolvedMember);
1425
1432
auto baseTy = CS.createTypeVariable (baseLocator, /* options=*/ 0 );
@@ -1434,7 +1441,8 @@ namespace {
1434
1441
// member, i.e., an enum case or a static variable.
1435
1442
auto baseMetaTy = MetatypeType::get (baseTy);
1436
1443
CS.addUnresolvedValueMemberConstraint (baseMetaTy, expr->getName (),
1437
- memberTy, memberLocator);
1444
+ memberTy, functionRefKind,
1445
+ memberLocator);
1438
1446
1439
1447
// If there is an argument, apply it.
1440
1448
if (auto arg = expr->getArgument ()) {
@@ -1494,7 +1502,7 @@ namespace {
1494
1502
/* options=*/ 0 );
1495
1503
auto methodTy = FunctionType::get (argsTy, resultTy);
1496
1504
CS.addValueMemberConstraint (baseTy, expr->getName (),
1497
- methodTy,
1505
+ methodTy, expr-> getFunctionRefKind (),
1498
1506
CS.getConstraintLocator (expr, ConstraintLocator::ConstructorMember));
1499
1507
1500
1508
// The result of the expression is the partial application of the
@@ -1503,7 +1511,7 @@ namespace {
1503
1511
}
1504
1512
1505
1513
return addMemberRefConstraints (expr, expr->getBase (), expr->getName (),
1506
- /* FIXME: */ FunctionRefKind::DoubleApply );
1514
+ expr-> getFunctionRefKind () );
1507
1515
}
1508
1516
1509
1517
Type visitUnresolvedSpecializeExpr (UnresolvedSpecializeExpr *expr) {
@@ -2495,7 +2503,9 @@ namespace {
2495
2503
if (CS.shouldAttemptFixes ()) {
2496
2504
Constraint *coerceConstraint =
2497
2505
Constraint::create (CS, ConstraintKind::ExplicitConversion,
2498
- fromType, toType, DeclName (), locator);
2506
+ fromType, toType, DeclName (),
2507
+ FunctionRefKind::Compound,
2508
+ locator);
2499
2509
Constraint *downcastConstraint =
2500
2510
Constraint::createFixed (CS, ConstraintKind::CheckedCast,
2501
2511
FixKind::CoerceToCheckedCast, fromType,
@@ -2730,10 +2740,14 @@ namespace {
2730
2740
// type-checked down to a call; turn it back into an overloaded
2731
2741
// member reference expression.
2732
2742
DeclNameLoc memberLoc;
2733
- if (auto member = findReferencedDecl (dotCall->getFn (), memberLoc)) {
2743
+ auto memberAndFunctionRef = findReferencedDecl (dotCall->getFn (),
2744
+ memberLoc);
2745
+ if (memberAndFunctionRef.first ) {
2734
2746
auto base = skipImplicitConversions (dotCall->getArg ());
2735
2747
return new (TC.Context ) MemberRefExpr (base,
2736
- dotCall->getDotLoc (), member, memberLoc,
2748
+ dotCall->getDotLoc (),
2749
+ memberAndFunctionRef.first ,
2750
+ memberLoc,
2737
2751
expr->isImplicit ());
2738
2752
}
2739
2753
}
@@ -2744,10 +2758,13 @@ namespace {
2744
2758
// actually matter; turn it back into an overloaded member reference
2745
2759
// expression.
2746
2760
DeclNameLoc memberLoc;
2747
- if (auto member = findReferencedDecl (dotIgnored->getRHS (), memberLoc)) {
2761
+ auto memberAndFunctionRef = findReferencedDecl (dotIgnored->getRHS (),
2762
+ memberLoc);
2763
+ if (memberAndFunctionRef.first ) {
2748
2764
auto base = skipImplicitConversions (dotIgnored->getLHS ());
2749
2765
return new (TC.Context ) MemberRefExpr (base,
2750
- dotIgnored->getDotLoc (), member,
2766
+ dotIgnored->getDotLoc (),
2767
+ memberAndFunctionRef.first ,
2751
2768
memberLoc, expr->isImplicit ());
2752
2769
}
2753
2770
}
@@ -3073,9 +3090,9 @@ Type swift::checkMemberType(DeclContext &DC, Type BaseTy,
3073
3090
TypeVariableOptions::TVO_CanBindToLValue);
3074
3091
CS.addConstraint (Constraint::createDisjunction (CS, {
3075
3092
Constraint::create (CS, ConstraintKind::TypeMember, Ty,
3076
- TV, DeclName (Id), Loc),
3093
+ TV, DeclName (Id), FunctionRefKind::Compound, Loc),
3077
3094
Constraint::create (CS, ConstraintKind::ValueMember, Ty,
3078
- TV, DeclName (Id), Loc)
3095
+ TV, DeclName (Id), FunctionRefKind::DoubleApply, Loc)
3079
3096
}, Loc));
3080
3097
Ty = TV;
3081
3098
}
@@ -3172,7 +3189,8 @@ bool swift::isExtensionApplied(DeclContext &DC, Type BaseTy,
3172
3189
return ;
3173
3190
}
3174
3191
// 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));
3176
3194
};
3177
3195
3178
3196
// For every requirement, add a constraint.
@@ -3221,6 +3239,7 @@ static bool canSatisfy(Type T1, Type T2, DeclContext &DC, ConstraintKind Kind,
3221
3239
T2 = T2.transform (Trans);
3222
3240
}
3223
3241
CS.addConstraint (Constraint::create (CS, Kind, T1, T2, DeclName (),
3242
+ FunctionRefKind::Compound,
3224
3243
CS.getConstraintLocator (nullptr )));
3225
3244
SmallVector<Solution, 4 > Solutions;
3226
3245
return AllowFreeVariables ?
@@ -3252,7 +3271,8 @@ swift::resolveValueMember(DeclContext &DC, Type BaseTy, DeclName Name) {
3252
3271
}
3253
3272
ConstraintSystem CS (*TC, &DC, None);
3254
3273
MemberLookupResult LookupResult = CS.performMemberLookup (
3255
- ConstraintKind::ValueMember, Name, BaseTy, nullptr , false );
3274
+ ConstraintKind::ValueMember, Name, BaseTy, FunctionRefKind::DoubleApply,
3275
+ nullptr , false );
3256
3276
if (LookupResult.ViableCandidates .empty ())
3257
3277
return Result;
3258
3278
ConstraintLocator *Locator = CS.getConstraintLocator (nullptr );
0 commit comments