Skip to content

Commit 1c732dd

Browse files
authored
Merge pull request #25574 from rintaro/ide-completion-init-for-unresolved-rdar49480808
[CodeCompleiton] Don't hide members for unresolved base types
2 parents 585ebbd + 032c6e6 commit 1c732dd

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
@@ -3791,7 +3791,8 @@ bool swift::isExtensionApplied(const DeclContext *DC, Type BaseTy,
37913791
const ExtensionDecl *ED) {
37923792
// We can't do anything if the base type has unbound generic parameters.
37933793
// We can't leak type variables into another constraint system.
3794-
if (BaseTy->hasTypeVariable() || BaseTy->hasUnboundGenericType())
3794+
if (BaseTy->hasTypeVariable() || BaseTy->hasUnboundGenericType() ||
3795+
BaseTy->hasUnresolvedType() || BaseTy->hasError())
37953796
return true;
37963797

37973798
if (!ED->isConstrainedExtension())
@@ -3811,7 +3812,8 @@ bool swift::isMemberDeclApplied(const DeclContext *DC, Type BaseTy,
38113812
const ValueDecl *VD) {
38123813
// We can't leak type variables into another constraint system.
38133814
// We can't do anything if the base type has unbound generic parameters.
3814-
if (BaseTy->hasTypeVariable() || BaseTy->hasUnboundGenericType())
3815+
if (BaseTy->hasTypeVariable() || BaseTy->hasUnboundGenericType()||
3816+
BaseTy->hasUnresolvedType() || BaseTy->hasError())
38153817
return true;
38163818

38173819
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)