Skip to content

[5.1][CodeCompleiton] Don't hide members for unresolved base types #25579

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/Sema/CSGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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();
Expand Down
14 changes: 14 additions & 0 deletions test/IDE/complete_constructor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}

Expand Down Expand Up @@ -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<Data: DataType> 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
}