Skip to content

Commit d27484a

Browse files
committed
[IDE] Resolve [.]Type completion for (any P). to produce singleton metatype instead of existential metatype.
Resolves #65843
1 parent bc4eeb8 commit d27484a

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

lib/IDE/CompletionLookup.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2440,8 +2440,13 @@ void CompletionLookup::getPostfixKeywordCompletions(Type ExprType,
24402440
if (instanceTy->isAnyExistentialType()) {
24412441
addKeyword("Protocol", MetatypeType::get(instanceTy),
24422442
SemanticContextKind::CurrentNominal);
2443-
addKeyword("Type", ExistentialMetatypeType::get(instanceTy),
2444-
SemanticContextKind::CurrentNominal);
2443+
if (instanceTy->hasParenSugar()) {
2444+
addKeyword("Type", MetatypeType::get(instanceTy),
2445+
SemanticContextKind::CurrentNominal);
2446+
} else {
2447+
addKeyword("Type", ExistentialMetatypeType::get(instanceTy),
2448+
SemanticContextKind::CurrentNominal);
2449+
}
24452450
} else {
24462451
addKeyword("Type", MetatypeType::get(instanceTy),
24472452
SemanticContextKind::CurrentNominal);

test/IDE/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)