Skip to content

Commit b8a1af3

Browse files
committed
[CodeCompleiton] Don't hide members for unresolved base types
Don't filter out members if the base type has unresolved types. Previously, initializers used to be hidden if the type has 'where' requirements on the generic parameters. This patch enables initializer completion for `SwiftUI.ForEach`. rdar://problem/49480808 (cherry picked from commit 032c6e6)
1 parent 979cc66 commit b8a1af3

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/Sema/CSGen.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3680,7 +3680,8 @@ bool swift::isExtensionApplied(const DeclContext *DC, Type BaseTy,
36803680
const ExtensionDecl *ED) {
36813681
// We can't do anything if the base type has unbound generic parameters.
36823682
// We can't leak type variables into another constraint system.
3683-
if (BaseTy->hasTypeVariable() || BaseTy->hasUnboundGenericType())
3683+
if (BaseTy->hasTypeVariable() || BaseTy->hasUnboundGenericType() ||
3684+
BaseTy->hasUnresolvedType() || BaseTy->hasError())
36843685
return true;
36853686

36863687
if (!ED->isConstrainedExtension())
@@ -3700,7 +3701,8 @@ bool swift::isMemberDeclApplied(const DeclContext *DC, Type BaseTy,
37003701
const ValueDecl *VD) {
37013702
// We can't leak type variables into another constraint system.
37023703
// We can't do anything if the base type has unbound generic parameters.
3703-
if (BaseTy->hasTypeVariable() || BaseTy->hasUnboundGenericType())
3704+
if (BaseTy->hasTypeVariable() || BaseTy->hasUnboundGenericType()||
3705+
BaseTy->hasUnresolvedType() || BaseTy->hasError())
37043706
return true;
37053707

37063708
const GenericContext *genericDecl = VD->getAsGenericContext();

test/IDE/complete_constructor.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252

5353
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=DEPENDENT_IN_CLOSURE_1 | %FileCheck %s -check-prefix=DEPENDENT_IN_CLOSURE_1
5454
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=DEPENDENT_IN_CLOSURE_2 | %FileCheck %s -check-prefix=DEPENDENT_IN_CLOSURE_2
55+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=INIT_WITH_UNRESOLVEDTYPE_1 | %FileCheck %s -check-prefix=INIT_WITH_UNRESOLVEDTYPE_1
5556

5657
func freeFunc() {}
5758

@@ -396,3 +397,16 @@ func testDependentTypeInClosure() {
396397
// DEPENDENT_IN_CLOSURE_2-DAG: Decl[Constructor]/CurrNominal: init({#arg: _#}, {#fn: () -> _.Content##() -> _.Content#})[#DependentTypeInClosure<_>#]; name=init(arg: _, fn: () -> _.Content)
397398
// DEPENDENT_IN_CLOSURE_2: End completions
398399
}
400+
struct InitWithUnresolved<Data: DataType> where Data.Content: Comparable {
401+
init(arg: Data, fn: (Data.Content) -> Void) {}
402+
}
403+
extension InitWithUnresolved where Self.Data: Comparable {
404+
init(arg2: Data) {}
405+
}
406+
func testInitWithUnresolved() {
407+
let _ = InitWithUnresolved(#^INIT_WITH_UNRESOLVEDTYPE_1^#
408+
// INIT_WITH_UNRESOLVEDTYPE_1: Begin completions, 2 items
409+
// INIT_WITH_UNRESOLVEDTYPE_1-DAG: Decl[Constructor]/CurrNominal: ['(']{#arg: _#}, {#fn: (_.Content) -> Void##(_.Content) -> Void#}[')'][#InitWithUnresolved<_>#];
410+
// INIT_WITH_UNRESOLVEDTYPE_1-DAG: Decl[Constructor]/CurrNominal: ['(']{#arg2: _#}[')'][#InitWithUnresolved<_>#];
411+
// INIT_WITH_UNRESOLVEDTYPE_1: End completions
412+
}

0 commit comments

Comments
 (0)