Skip to content

Commit de412bb

Browse files
committed
[IDE] Pass whether we have applied self to replaceParamErrorTypeByPlaceholder
1 parent 64e92d2 commit de412bb

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

lib/Sema/ConstraintSystem.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,30 +1523,35 @@ AnyFunctionType *ConstraintSystem::adjustFunctionTypeForConcurrency(
15231523
/// that declared \p type. This is useful for code completion so we can match
15241524
/// the types we do know instead of bailing out completely because \p type
15251525
/// contains an error type.
1526-
static Type replaceParamErrorTypeByPlaceholder(Type type, ValueDecl *value) {
1526+
static Type replaceParamErrorTypeByPlaceholder(Type type, ValueDecl *value, bool hasAppliedSelf) {
15271527
if (!type->is<AnyFunctionType>() || !isa<AbstractFunctionDecl>(value)) {
15281528
return type;
15291529
}
15301530
auto funcType = type->castTo<AnyFunctionType>();
15311531
auto funcDecl = cast<AbstractFunctionDecl>(value);
15321532

1533-
auto declParams = funcDecl->getParameters();
1533+
SmallVector<ParamDecl *> declParams;
1534+
if (hasAppliedSelf) {
1535+
declParams.append(funcDecl->getParameters()->begin(), funcDecl->getParameters()->end());
1536+
} else {
1537+
declParams.push_back(funcDecl->getImplicitSelfDecl());
1538+
}
15341539
auto typeParams = funcType->getParams();
1535-
assert(declParams->size() == typeParams.size());
1540+
assert(declParams.size() == typeParams.size());
15361541
SmallVector<AnyFunctionType::Param, 4> newParams;
1537-
newParams.reserve(declParams->size());
1542+
newParams.reserve(declParams.size());
15381543
for (auto i : indices(typeParams)) {
15391544
AnyFunctionType::Param param = typeParams[i];
15401545
if (param.getPlainType()->is<ErrorType>()) {
1541-
auto paramDecl = declParams->get(i);
1546+
auto paramDecl = declParams[i];
15421547
auto placeholder =
15431548
PlaceholderType::get(paramDecl->getASTContext(), paramDecl);
15441549
newParams.push_back(param.withType(placeholder));
15451550
} else {
15461551
newParams.push_back(param);
15471552
}
15481553
}
1549-
assert(newParams.size() == declParams->size());
1554+
assert(newParams.size() == declParams.size());
15501555
return FunctionType::get(newParams, funcType->getResult());
15511556
}
15521557

@@ -1617,7 +1622,7 @@ ConstraintSystem::getTypeOfReference(ValueDecl *value,
16171622
if (isForCodeCompletion() && openedType->hasError()) {
16181623
// In code completion, replace error types by placeholder types so we can
16191624
// match the types we know instead of bailing out completely.
1620-
openedType = replaceParamErrorTypeByPlaceholder(openedType, value);
1625+
openedType = replaceParamErrorTypeByPlaceholder(openedType, value, /*hasAppliedSelf=*/true);
16211626
}
16221627

16231628
// If we opened up any type variables, record the replacements.
@@ -2285,7 +2290,7 @@ Type ConstraintSystem::getMemberReferenceTypeFromOpenedType(
22852290
if (isForCodeCompletion() && type->hasError()) {
22862291
// In code completion, replace error types by placeholder types so we can
22872292
// match the types we know instead of bailing out completely.
2288-
type = replaceParamErrorTypeByPlaceholder(type, value);
2293+
type = replaceParamErrorTypeByPlaceholder(type, value, hasAppliedSelf);
22892294
}
22902295

22912296
return type;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-ide-test -batch-code-completion -source-filename %s -filecheck %raw-FileCheck -completion-output-dir %t
3+
4+
struct Test {
5+
func myMethod() -> Invalid {}
6+
7+
func test() {
8+
Test.myMethod#^COMPLETE^#
9+
}
10+
}
11+
12+
// Check that we don't crash
13+
// COMPLETE-NOT: Begin completions

0 commit comments

Comments
 (0)