Skip to content

Commit 1f0eb6d

Browse files
committed
[IDE] Resolve [.]Type completion for (any P). to produce singleton metatype instead of existential metatype.
Resolves #65843 The type completion for (any P). is a singleton meta type which currently falsely produces any P., i.e, an existential meta type.
1 parent a92f379 commit 1f0eb6d

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

lib/IDE/CompletionLookup.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2475,8 +2475,16 @@ void CompletionLookup::getPostfixKeywordCompletions(Type ExprType,
24752475
if (instanceTy->isAnyExistentialType()) {
24762476
addKeyword("Protocol", MetatypeType::get(instanceTy),
24772477
SemanticContextKind::CurrentNominal);
2478-
addKeyword("Type", ExistentialMetatypeType::get(instanceTy),
2479-
SemanticContextKind::CurrentNominal);
2478+
if (auto *typeExpr = dyn_cast<TypeExpr>(ParsedExpr)) {
2479+
if (auto *typeRepr = typeExpr->getTypeRepr()) {
2480+
if (typeRepr->isParenType())
2481+
addKeyword("Type", MetatypeType::get(instanceTy),
2482+
SemanticContextKind::CurrentNominal);
2483+
else
2484+
addKeyword("Type", ExistentialMetatypeType::get(instanceTy),
2485+
SemanticContextKind::CurrentNominal);
2486+
}
2487+
}
24802488
} else {
24812489
addKeyword("Type", MetatypeType::get(instanceTy),
24822490
SemanticContextKind::CurrentNominal);

test/IDE/complete_issue-65843.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
protocol P {}
5+
6+
(any P).#^COMPLETE?^#
7+
// COMPLETE: Begin completions, 3 items
8+
// COMPLETE: Keyword[self]/CurrNominal: self[#(any P).Type#]; name=self
9+
// COMPLETE: Keyword/CurrNominal: Protocol[#(any P).Type#]; name=Protocol
10+
// COMPLETE: Keyword/CurrNominal: Type[#(any P).Type#]; name=Type
11+
12+
13+
P.Type.#^PROTOCOLTYPE_DOT_1?^#
14+
// PROTOCOLTYPE_DOT_1: Begin completions, 3 items
15+
// PROTOCOLTYPE_DOT_1: Keyword[self]/CurrNominal: self[#(any P.Type).Type#]; name=self
16+
// PROTOCOLTYPE_DOT_1: Keyword/CurrNominal: Protocol[#(any P.Type).Type#]; name=Protocol
17+
// PROTOCOLTYPE_DOT_1: Keyword/CurrNominal: Type[#any P.Type.Type#]; name=Type
18+
19+
(P).Type.#^PROTOCOLTYPE_DOT_2?^#
20+
// PROTOCOLTYPE_DOT_2: Begin completions, 3 items
21+
// PROTOCOLTYPE_DOT_2: Keyword[self]/CurrNominal: self[#(any (P).Type).Type#]; name=self
22+
// PROTOCOLTYPE_DOT_2: Keyword/CurrNominal: Protocol[#(any (P).Type).Type#]; name=Protocol
23+
// PROTOCOLTYPE_DOT_2: Keyword/CurrNominal: Type[#any (P).Type.Type#]; name=Type

0 commit comments

Comments
 (0)