Skip to content

Commit

Permalink
[IDE] Resolve [.]Type completion for (any P). to produce singleto…
Browse files Browse the repository at this point in the history
…n metatype instead of existential metatype.

Resolves swiftlang#65843
  • Loading branch information
Rajveer100 committed Apr 24, 2024
1 parent bc4eeb8 commit d27484a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/IDE/CompletionLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2440,8 +2440,13 @@ void CompletionLookup::getPostfixKeywordCompletions(Type ExprType,
if (instanceTy->isAnyExistentialType()) {
addKeyword("Protocol", MetatypeType::get(instanceTy),
SemanticContextKind::CurrentNominal);
addKeyword("Type", ExistentialMetatypeType::get(instanceTy),
SemanticContextKind::CurrentNominal);
if (instanceTy->hasParenSugar()) {
addKeyword("Type", MetatypeType::get(instanceTy),
SemanticContextKind::CurrentNominal);
} else {
addKeyword("Type", ExistentialMetatypeType::get(instanceTy),
SemanticContextKind::CurrentNominal);
}
} else {
addKeyword("Type", MetatypeType::get(instanceTy),
SemanticContextKind::CurrentNominal);
Expand Down
23 changes: 23 additions & 0 deletions test/IDE/issue-65843.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-ide-test -batch-code-completion -source-filename %s -filecheck %raw-FileCheck -completion-output-dir %t

protocol P {}

(any P).#^COMPLETE?^#
// COMPLETE: Begin completions, 3 items
// COMPLETE: Keyword[self]/CurrNominal: self[#(any P).Type#]; name=self
// COMPLETE: Keyword/CurrNominal: Protocol[#(any P).Type#]; name=Protocol
// COMPLETE: Keyword/CurrNominal: Type[#(any P).Type#]; name=Type


P.Type.#^PROTOCOLTYPE_DOT_1?^#
// PROTOCOLTYPE_DOT_1: Begin completions, 3 items
// PROTOCOLTYPE_DOT_1: Keyword[self]/CurrNominal: self[#(any P.Type).Type#]; name=self
// PROTOCOLTYPE_DOT_1: Keyword/CurrNominal: Protocol[#(any P.Type).Type#]; name=Protocol
// PROTOCOLTYPE_DOT_1: Keyword/CurrNominal: Type[#any P.Type.Type#]; name=Type

(P).Type.#^PROTOCOLTYPE_DOT_2?^#
// PROTOCOLTYPE_DOT_2: Begin completions, 3 items
// PROTOCOLTYPE_DOT_2: Keyword[self]/CurrNominal: self[#(any (P).Type).Type#]; name=self
// PROTOCOLTYPE_DOT_2: Keyword/CurrNominal: Protocol[#(any (P).Type).Type#]; name=Protocol
// PROTOCOLTYPE_DOT_2: Keyword/CurrNominal: Type[#any (P).Type.Type#]; name=Type

0 comments on commit d27484a

Please sign in to comment.