@@ -4971,11 +4971,11 @@ namespace {
4971
4971
} // end anonymous namespace
4972
4972
4973
4973
namespace {
4974
- using FunctionParams = ArrayRef<AnyFunctionType::Param >;
4974
+ using FunctionTypeAndDecl = std::pair<AnyFunctionType *, ValueDecl * >;
4975
4975
4976
- void collectPossibleParamListByQualifiedLookup (
4976
+ void collectPossibleCalleesByQualifiedLookup (
4977
4977
DeclContext &DC, Type baseTy, DeclBaseName name,
4978
- SmallVectorImpl<FunctionParams > &candidates) {
4978
+ SmallVectorImpl<FunctionTypeAndDecl > &candidates) {
4979
4979
4980
4980
SmallVector<ValueDecl *, 2 > decls;
4981
4981
auto resolver = DC.getASTContext ().getLazyResolver ();
@@ -5000,14 +5000,14 @@ void collectPossibleParamListByQualifiedLookup(
5000
5000
if (!fnType || fnType->hasError ())
5001
5001
continue ;
5002
5002
if (auto *AFT = fnType->getAs <AnyFunctionType>()) {
5003
- candidates.push_back (AFT-> getParams () );
5003
+ candidates.emplace_back (AFT, VD );
5004
5004
}
5005
5005
}
5006
5006
}
5007
5007
5008
- void collectPossibleParamListByQualifiedLookup (
5008
+ void collectPossibleCalleesByQualifiedLookup (
5009
5009
DeclContext &DC, Expr *baseExpr, DeclBaseName name,
5010
- SmallVectorImpl<FunctionParams > &candidates) {
5010
+ SmallVectorImpl<FunctionTypeAndDecl > &candidates) {
5011
5011
ConcreteDeclRef ref = nullptr ;
5012
5012
auto baseTyOpt = getTypeOfCompletionContextExpr (
5013
5013
DC.getASTContext (), &DC, CompletionTypeCheckKind::Normal, baseExpr, ref);
@@ -5017,31 +5017,31 @@ void collectPossibleParamListByQualifiedLookup(
5017
5017
if (!baseTy->mayHaveMembers ())
5018
5018
return ;
5019
5019
5020
- collectPossibleParamListByQualifiedLookup (DC, baseTy, name, candidates);
5020
+ collectPossibleCalleesByQualifiedLookup (DC, baseTy, name, candidates);
5021
5021
}
5022
5022
5023
- bool collectPossibleParamListsApply (
5023
+ bool collectPossibleCalleesForApply (
5024
5024
DeclContext &DC, ApplyExpr *callExpr,
5025
- SmallVectorImpl<FunctionParams > &candidates) {
5025
+ SmallVectorImpl<FunctionTypeAndDecl > &candidates) {
5026
5026
auto *fnExpr = callExpr->getFn ();
5027
5027
5028
5028
if (auto type = fnExpr->getType ()) {
5029
5029
if (auto *funcType = type->getAs <AnyFunctionType>())
5030
- candidates.push_back (funcType-> getParams ());
5030
+ candidates.emplace_back (funcType, fnExpr-> getReferencedDecl (). getDecl ());
5031
5031
} else if (auto *DRE = dyn_cast<DeclRefExpr>(fnExpr)) {
5032
5032
if (auto *decl = DRE->getDecl ()) {
5033
5033
auto declType = decl->getInterfaceType ();
5034
5034
if (auto *funcType = declType->getAs <AnyFunctionType>())
5035
- candidates.push_back (funcType-> getParams () );
5035
+ candidates.emplace_back (funcType, decl );
5036
5036
}
5037
5037
} else if (auto *OSRE = dyn_cast<OverloadSetRefExpr>(fnExpr)) {
5038
5038
for (auto *decl : OSRE->getDecls ()) {
5039
5039
auto declType = decl->getInterfaceType ();
5040
5040
if (auto *funcType = declType->getAs <AnyFunctionType>())
5041
- candidates.push_back (funcType-> getParams () );
5041
+ candidates.emplace_back (funcType, decl );
5042
5042
}
5043
5043
} else if (auto *UDE = dyn_cast<UnresolvedDotExpr>(fnExpr)) {
5044
- collectPossibleParamListByQualifiedLookup (
5044
+ collectPossibleCalleesByQualifiedLookup (
5045
5045
DC, UDE->getBase (), UDE->getName ().getBaseName (), candidates);
5046
5046
}
5047
5047
@@ -5053,31 +5053,31 @@ bool collectPossibleParamListsApply(
5053
5053
return false ;
5054
5054
5055
5055
if (auto *AFT = (*fnType)->getAs <AnyFunctionType>()) {
5056
- candidates.push_back (AFT-> getParams ());
5056
+ candidates.emplace_back (AFT, ref. getDecl ());
5057
5057
} else if (auto *AMT = (*fnType)->getAs <AnyMetatypeType>()) {
5058
5058
auto baseTy = AMT->getInstanceType ();
5059
5059
if (baseTy->mayHaveMembers ())
5060
- collectPossibleParamListByQualifiedLookup (
5060
+ collectPossibleCalleesByQualifiedLookup (
5061
5061
DC, baseTy, DeclBaseName::createConstructor (), candidates);
5062
5062
}
5063
5063
}
5064
5064
5065
5065
return !candidates.empty ();
5066
5066
}
5067
5067
5068
- bool collectPossibleParamListsSubscript (
5068
+ bool collectPossibleCalleesForSubscript (
5069
5069
DeclContext &DC, SubscriptExpr *subscriptExpr,
5070
- SmallVectorImpl<FunctionParams > &candidates) {
5070
+ SmallVectorImpl<FunctionTypeAndDecl > &candidates) {
5071
5071
if (subscriptExpr->hasDecl ()) {
5072
5072
if (auto SD = dyn_cast<SubscriptDecl>(subscriptExpr->getDecl ().getDecl ())) {
5073
5073
auto declType = SD->getInterfaceType ();
5074
5074
if (auto *funcType = declType->getAs <AnyFunctionType>())
5075
- candidates.push_back (funcType-> getParams () );
5075
+ candidates.emplace_back (funcType, SD );
5076
5076
}
5077
5077
} else {
5078
- collectPossibleParamListByQualifiedLookup (DC, subscriptExpr->getBase (),
5079
- DeclBaseName::createSubscript (),
5080
- candidates);
5078
+ collectPossibleCalleesByQualifiedLookup (DC, subscriptExpr->getBase (),
5079
+ DeclBaseName::createSubscript (),
5080
+ candidates);
5081
5081
}
5082
5082
return !candidates.empty ();
5083
5083
}
@@ -5166,14 +5166,14 @@ class CodeCompletionTypeContextAnalyzer {
5166
5166
5167
5167
bool collectArgumentExpectation (DeclContext &DC, Expr *E, Expr *CCExpr) {
5168
5168
// Collect parameter lists for possible func decls.
5169
- SmallVector<FunctionParams , 4 > Candidates;
5169
+ SmallVector<FunctionTypeAndDecl , 4 > Candidates;
5170
5170
Expr *Arg = nullptr ;
5171
5171
if (auto *applyExpr = dyn_cast<ApplyExpr>(E)) {
5172
- if (!collectPossibleParamListsApply (DC, applyExpr, Candidates))
5172
+ if (!collectPossibleCalleesForApply (DC, applyExpr, Candidates))
5173
5173
return false ;
5174
5174
Arg = applyExpr->getArg ();
5175
5175
} else if (auto *subscriptExpr = dyn_cast<SubscriptExpr>(E)) {
5176
- if (!collectPossibleParamListsSubscript (DC, subscriptExpr, Candidates))
5176
+ if (!collectPossibleCalleesForSubscript (DC, subscriptExpr, Candidates))
5177
5177
return false ;
5178
5178
Arg = subscriptExpr->getIndex ();
5179
5179
}
@@ -5192,7 +5192,8 @@ class CodeCompletionTypeContextAnalyzer {
5192
5192
(isa<CallExpr>(E) | isa<SubscriptExpr>(E));
5193
5193
SmallPtrSet<TypeBase *, 4 > seenTypes;
5194
5194
SmallPtrSet<Identifier, 4 > seenNames;
5195
- for (auto Params : Candidates) {
5195
+ for (auto &typeAndDecl : Candidates) {
5196
+ auto Params = typeAndDecl.first ->getParams ();
5196
5197
if (Position >= Params.size ())
5197
5198
continue ;
5198
5199
const auto &Param = Params[Position];
0 commit comments