mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[CodeComplete] Avoid using an unresolved contextual type
This can occur for e.g multi-statement closure returns (and soon for singe-expression closures too), so fall back to evaluating the expression type if it's not fully resolved.
This commit is contained in:
@@ -47,8 +47,11 @@ void TypeCheckCompletionCallback::fallbackTypeCheck(DeclContext *DC) {
|
||||
|
||||
Type swift::ide::getTypeForCompletion(const constraints::Solution &S,
|
||||
ASTNode Node) {
|
||||
// Use the contextual type, unless it is still unresolved, in which case fall
|
||||
// back to getting the type from the expression.
|
||||
if (auto ContextualType = S.getContextualType(Node)) {
|
||||
return ContextualType;
|
||||
if (!ContextualType->hasUnresolvedType())
|
||||
return ContextualType;
|
||||
}
|
||||
|
||||
if (!S.hasType(Node)) {
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
// 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
|
||||
// RUN: %batch-code-completion
|
||||
|
||||
// https://github.com/apple/swift/issues/55711
|
||||
// https://forums.swift.org/t/code-completion-enhancement-request/38677
|
||||
@@ -37,6 +35,10 @@ func test() {
|
||||
C(.a) {
|
||||
.#^A^#
|
||||
}
|
||||
C(.a) {
|
||||
()
|
||||
return .#^A_MULTISTMT?check=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>#];
|
||||
|
||||
Reference in New Issue
Block a user