@@ -5093,11 +5093,11 @@ namespace {
5093
5093
} // end anonymous namespace
5094
5094
5095
5095
namespace {
5096
- using FunctionParams = ArrayRef<AnyFunctionType::Param >;
5096
+ using FunctionTypeAndDecl = std::pair<AnyFunctionType *, ValueDecl * >;
5097
5097
5098
- void collectPossibleParamListByQualifiedLookup (
5098
+ void collectPossibleCalleesByQualifiedLookup (
5099
5099
DeclContext &DC, Type baseTy, DeclBaseName name,
5100
- SmallVectorImpl<FunctionParams > &candidates) {
5100
+ SmallVectorImpl<FunctionTypeAndDecl > &candidates) {
5101
5101
5102
5102
SmallVector<ValueDecl *, 2 > decls;
5103
5103
auto resolver = DC.getASTContext ().getLazyResolver ();
@@ -5122,14 +5122,14 @@ void collectPossibleParamListByQualifiedLookup(
5122
5122
if (!fnType || fnType->hasError ())
5123
5123
continue ;
5124
5124
if (auto *AFT = fnType->getAs <AnyFunctionType>()) {
5125
- candidates.push_back (AFT-> getParams () );
5125
+ candidates.emplace_back (AFT, VD );
5126
5126
}
5127
5127
}
5128
5128
}
5129
5129
5130
- void collectPossibleParamListByQualifiedLookup (
5130
+ void collectPossibleCalleesByQualifiedLookup (
5131
5131
DeclContext &DC, Expr *baseExpr, DeclBaseName name,
5132
- SmallVectorImpl<FunctionParams > &candidates) {
5132
+ SmallVectorImpl<FunctionTypeAndDecl > &candidates) {
5133
5133
ConcreteDeclRef ref = nullptr ;
5134
5134
auto baseTyOpt = getTypeOfCompletionContextExpr (
5135
5135
DC.getASTContext (), &DC, CompletionTypeCheckKind::Normal, baseExpr, ref);
@@ -5139,31 +5139,31 @@ void collectPossibleParamListByQualifiedLookup(
5139
5139
if (!baseTy->mayHaveMembers ())
5140
5140
return ;
5141
5141
5142
- collectPossibleParamListByQualifiedLookup (DC, baseTy, name, candidates);
5142
+ collectPossibleCalleesByQualifiedLookup (DC, baseTy, name, candidates);
5143
5143
}
5144
5144
5145
- bool collectPossibleParamListsApply (
5145
+ bool collectPossibleCalleesForApply (
5146
5146
DeclContext &DC, ApplyExpr *callExpr,
5147
- SmallVectorImpl<FunctionParams > &candidates) {
5147
+ SmallVectorImpl<FunctionTypeAndDecl > &candidates) {
5148
5148
auto *fnExpr = callExpr->getFn ();
5149
5149
5150
5150
if (auto type = fnExpr->getType ()) {
5151
5151
if (auto *funcType = type->getAs <AnyFunctionType>())
5152
- candidates.push_back (funcType-> getParams ());
5152
+ candidates.emplace_back (funcType, fnExpr-> getReferencedDecl (). getDecl ());
5153
5153
} else if (auto *DRE = dyn_cast<DeclRefExpr>(fnExpr)) {
5154
5154
if (auto *decl = DRE->getDecl ()) {
5155
5155
auto declType = decl->getInterfaceType ();
5156
5156
if (auto *funcType = declType->getAs <AnyFunctionType>())
5157
- candidates.push_back (funcType-> getParams () );
5157
+ candidates.emplace_back (funcType, decl );
5158
5158
}
5159
5159
} else if (auto *OSRE = dyn_cast<OverloadSetRefExpr>(fnExpr)) {
5160
5160
for (auto *decl : OSRE->getDecls ()) {
5161
5161
auto declType = decl->getInterfaceType ();
5162
5162
if (auto *funcType = declType->getAs <AnyFunctionType>())
5163
- candidates.push_back (funcType-> getParams () );
5163
+ candidates.emplace_back (funcType, decl );
5164
5164
}
5165
5165
} else if (auto *UDE = dyn_cast<UnresolvedDotExpr>(fnExpr)) {
5166
- collectPossibleParamListByQualifiedLookup (
5166
+ collectPossibleCalleesByQualifiedLookup (
5167
5167
DC, UDE->getBase (), UDE->getName ().getBaseName (), candidates);
5168
5168
}
5169
5169
@@ -5175,31 +5175,31 @@ bool collectPossibleParamListsApply(
5175
5175
return false ;
5176
5176
5177
5177
if (auto *AFT = (*fnType)->getAs <AnyFunctionType>()) {
5178
- candidates.push_back (AFT-> getParams ());
5178
+ candidates.emplace_back (AFT, ref. getDecl ());
5179
5179
} else if (auto *AMT = (*fnType)->getAs <AnyMetatypeType>()) {
5180
5180
auto baseTy = AMT->getInstanceType ();
5181
5181
if (baseTy->mayHaveMembers ())
5182
- collectPossibleParamListByQualifiedLookup (
5182
+ collectPossibleCalleesByQualifiedLookup (
5183
5183
DC, baseTy, DeclBaseName::createConstructor (), candidates);
5184
5184
}
5185
5185
}
5186
5186
5187
5187
return !candidates.empty ();
5188
5188
}
5189
5189
5190
- bool collectPossibleParamListsSubscript (
5190
+ bool collectPossibleCalleesForSubscript (
5191
5191
DeclContext &DC, SubscriptExpr *subscriptExpr,
5192
- SmallVectorImpl<FunctionParams > &candidates) {
5192
+ SmallVectorImpl<FunctionTypeAndDecl > &candidates) {
5193
5193
if (subscriptExpr->hasDecl ()) {
5194
5194
if (auto SD = dyn_cast<SubscriptDecl>(subscriptExpr->getDecl ().getDecl ())) {
5195
5195
auto declType = SD->getInterfaceType ();
5196
5196
if (auto *funcType = declType->getAs <AnyFunctionType>())
5197
- candidates.push_back (funcType-> getParams () );
5197
+ candidates.emplace_back (funcType, SD );
5198
5198
}
5199
5199
} else {
5200
- collectPossibleParamListByQualifiedLookup (DC, subscriptExpr->getBase (),
5201
- DeclBaseName::createSubscript (),
5202
- candidates);
5200
+ collectPossibleCalleesByQualifiedLookup (DC, subscriptExpr->getBase (),
5201
+ DeclBaseName::createSubscript (),
5202
+ candidates);
5203
5203
}
5204
5204
return !candidates.empty ();
5205
5205
}
@@ -5288,14 +5288,14 @@ class CodeCompletionTypeContextAnalyzer {
5288
5288
5289
5289
bool collectArgumentExpectation (DeclContext &DC, Expr *E, Expr *CCExpr) {
5290
5290
// Collect parameter lists for possible func decls.
5291
- SmallVector<FunctionParams , 4 > Candidates;
5291
+ SmallVector<FunctionTypeAndDecl , 4 > Candidates;
5292
5292
Expr *Arg = nullptr ;
5293
5293
if (auto *applyExpr = dyn_cast<ApplyExpr>(E)) {
5294
- if (!collectPossibleParamListsApply (DC, applyExpr, Candidates))
5294
+ if (!collectPossibleCalleesForApply (DC, applyExpr, Candidates))
5295
5295
return false ;
5296
5296
Arg = applyExpr->getArg ();
5297
5297
} else if (auto *subscriptExpr = dyn_cast<SubscriptExpr>(E)) {
5298
- if (!collectPossibleParamListsSubscript (DC, subscriptExpr, Candidates))
5298
+ if (!collectPossibleCalleesForSubscript (DC, subscriptExpr, Candidates))
5299
5299
return false ;
5300
5300
Arg = subscriptExpr->getIndex ();
5301
5301
}
@@ -5314,7 +5314,8 @@ class CodeCompletionTypeContextAnalyzer {
5314
5314
(isa<CallExpr>(E) | isa<SubscriptExpr>(E));
5315
5315
SmallPtrSet<TypeBase *, 4 > seenTypes;
5316
5316
SmallPtrSet<Identifier, 4 > seenNames;
5317
- for (auto Params : Candidates) {
5317
+ for (auto &typeAndDecl : Candidates) {
5318
+ auto Params = typeAndDecl.first ->getParams ();
5318
5319
if (Position >= Params.size ())
5319
5320
continue ;
5320
5321
const auto &Param = Params[Position];
0 commit comments