Files
swift-mirror/test/IDE/complete_sr13271.swift
Nathan Hawes ca7fb37aba [CodeCompletion][Sema][Parse] Migrate unresolved member completion to the solver-based completion implementation
Following on from updating regular member completion, this hooks up unresolved
member completion (i.e. .<complete here>) to the typeCheckForCodeCompletion API
to generate completions from all solutions the constraint solver produces (even
those requiring fixes), rather than relying on a single solution being applied
to the AST (if any). This lets us produce unresolved member completions even
when the contextual type is ambiguous or involves errors.

Whenever typeCheckExpression is called on an expression containing a code
completion expression and a CompletionCallback has been set, each solution
formed is passed to the callback so the type of the completion expression can
be extracted and used to lookup up the members to return.
2020-11-13 15:37:14 -08:00

67 lines
1.6 KiB
Swift

// RUN: %swift-ide-test -code-completion -source-filename=%s -code-completion-token=A | %FileCheck %s --check-prefix=A
// RUN: %swift-ide-test -code-completion -source-filename=%s -code-completion-token=B | %FileCheck %s --check-prefix=B
// RUN: %swift-ide-test -code-completion -source-filename=%s -code-completion-token=D | %FileCheck %s --check-prefix=D
// https://bugs.swift.org/browse/SR-13271
// https://forums.swift.org/t/code-completion-enhancement-request/38677
enum AIdentifier {
case a
}
enum BIdentifier {
case b
}
struct X { }
struct Y { }
struct A <T> {
private init(){}
static func foo (arg: Bool) -> A<X> { A<X>() }
static func bar (arg: Int) -> A<Y> { A<Y>() }
}
struct B {
static var baz: B { B() }
}
func C<T>(_ identifier: AIdentifier, _ a: ()->A<T>) -> D<T> { }
func C(_ identifier: BIdentifier, _ b: ()->B) { }
struct D <T> {
func sink (_ handler: @escaping (T)->()) { }
}
func test() {
C(.a) {
.#^A^#
}
// A: Begin completions, 2 items
// A-DAG: Decl[StaticMethod]/CurrNominal/TypeRelation[Convertible]: foo({#arg: Bool#})[#A<X>#];
// A-DAG: Decl[StaticMethod]/CurrNominal/TypeRelation[Convertible]: bar({#arg: Int#})[#A<Y>#];
// A: End completions
}
func test() {
C(.b) {
.#^B^#
}
// B: Begin completions, 2 items
// B-DAG: Decl[StaticVar]/ExprSpecific/TypeRelation[Identical]: baz[#B#]; name=baz
// B-DAG: Decl[Constructor]/CurrNominal/TypeRelation[Identical]: init()[#B#]; name=init()
// B: End completions
}
func test() {
C(.a) {
.foo(arg: true)
}
.sink { value in
value.#^D^#
}
// D: Begin completions, 1 items
// D-DAG: Keyword[self]/CurrNominal: self[#X#];
// D: End completions
}