From 891eba7e31016a04aefdb0ba109e900e713538c8 Mon Sep 17 00:00:00 2001 From: Rintaro Ishizaki Date: Tue, 18 Jun 2019 12:18:27 -0700 Subject: [PATCH] [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 032c6e647e567f8744e9c9ef6ca595fed8541181) --- lib/Sema/CSGen.cpp | 6 ++++-- test/IDE/complete_constructor.swift | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/Sema/CSGen.cpp b/lib/Sema/CSGen.cpp index e0a13f6e20487..f4c960c64d402 100644 --- a/lib/Sema/CSGen.cpp +++ b/lib/Sema/CSGen.cpp @@ -3680,7 +3680,8 @@ bool swift::isExtensionApplied(const DeclContext *DC, Type BaseTy, const ExtensionDecl *ED) { // We can't do anything if the base type has unbound generic parameters. // We can't leak type variables into another constraint system. - if (BaseTy->hasTypeVariable() || BaseTy->hasUnboundGenericType()) + if (BaseTy->hasTypeVariable() || BaseTy->hasUnboundGenericType() || + BaseTy->hasUnresolvedType() || BaseTy->hasError()) return true; if (!ED->isConstrainedExtension()) @@ -3700,7 +3701,8 @@ bool swift::isMemberDeclApplied(const DeclContext *DC, Type BaseTy, const ValueDecl *VD) { // We can't leak type variables into another constraint system. // We can't do anything if the base type has unbound generic parameters. - if (BaseTy->hasTypeVariable() || BaseTy->hasUnboundGenericType()) + if (BaseTy->hasTypeVariable() || BaseTy->hasUnboundGenericType()|| + BaseTy->hasUnresolvedType() || BaseTy->hasError()) return true; const GenericContext *genericDecl = VD->getAsGenericContext(); diff --git a/test/IDE/complete_constructor.swift b/test/IDE/complete_constructor.swift index 15529a371fc94..65d4457e21c4c 100644 --- a/test/IDE/complete_constructor.swift +++ b/test/IDE/complete_constructor.swift @@ -52,6 +52,7 @@ // 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 // 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 +// 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 func freeFunc() {} @@ -396,3 +397,16 @@ func testDependentTypeInClosure() { // DEPENDENT_IN_CLOSURE_2-DAG: Decl[Constructor]/CurrNominal: init({#arg: _#}, {#fn: () -> _.Content##() -> _.Content#})[#DependentTypeInClosure<_>#]; name=init(arg: _, fn: () -> _.Content) // DEPENDENT_IN_CLOSURE_2: End completions } +struct InitWithUnresolved where Data.Content: Comparable { + init(arg: Data, fn: (Data.Content) -> Void) {} +} +extension InitWithUnresolved where Self.Data: Comparable { + init(arg2: Data) {} +} +func testInitWithUnresolved() { + let _ = InitWithUnresolved(#^INIT_WITH_UNRESOLVEDTYPE_1^# +// INIT_WITH_UNRESOLVEDTYPE_1: Begin completions, 2 items +// INIT_WITH_UNRESOLVEDTYPE_1-DAG: Decl[Constructor]/CurrNominal: ['(']{#arg: _#}, {#fn: (_.Content) -> Void##(_.Content) -> Void#}[')'][#InitWithUnresolved<_>#]; +// INIT_WITH_UNRESOLVEDTYPE_1-DAG: Decl[Constructor]/CurrNominal: ['(']{#arg2: _#}[')'][#InitWithUnresolved<_>#]; +// INIT_WITH_UNRESOLVEDTYPE_1: End completions +}