Skip to content

Commit c3d1e34

Browse files
committed
[CodeCompletion] Do not include decl in own default argument
Similar to 4cf7426 but for the case when the completion is in a default argument expression rather than initializer. Fixed to grab either the initializer or default argument if there is one.
1 parent 95ae192 commit c3d1e34

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

lib/AST/NameLookup.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,14 @@ void UsableFilteringDeclConsumer::foundDecl(ValueDecl *D,
149149
DeclVisibilityKind reason, DynamicLookupInfo dynamicLookupInfo) {
150150
// Skip when Loc is within the decl's own initializer
151151
if (auto *VD = dyn_cast<VarDecl>(D)) {
152+
Expr *init = VD->getParentInitializer();
153+
if (auto *PD = dyn_cast<ParamDecl>(D)) {
154+
init = PD->getStructuralDefaultExpr();
155+
}
156+
152157
// Only check if the VarDecl has the same (or parent) context to avoid
153-
// grabbing the end location for every decl
154-
if (auto *init = VD->getParentInitializer()) {
158+
// grabbing the end location for every decl with an initializer
159+
if (init != nullptr) {
155160
auto *varContext = VD->getDeclContext();
156161
if (DC == varContext || DC->isChildContextOf(varContext)) {
157162
auto initRange = Lexer::getCharSourceRangeFromSourceRange(

test/IDE/complete_expr_postfix_begin.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@
7575
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=IN_TUPLE_1 | %FileCheck %s -check-prefix=IN_TUPLE_1
7676
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=IN_TUPLE_2 | %FileCheck %s -check-prefix=IN_TUPLE_2
7777

78-
// RUN-FIXME(rdar56755598): %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=OWN_INIT_1 | %FileCheck %s -check-prefix=OWN_INIT_1
79-
// RUN-FIXME(rdar56755598): %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=OWN_INIT_2 | %FileCheck %s -check-prefix=OWN_INIT_2
78+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=OWN_INIT_1 | %FileCheck %s -check-prefix=OWN_INIT_1
79+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=OWN_INIT_2 | %FileCheck %s -check-prefix=OWN_INIT_2
8080
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=OWN_INIT_3 | %FileCheck %s -check-prefix=OWN_INIT_3
8181
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=OWN_INIT_4 | %FileCheck %s -check-prefix=OWN_INIT_4
8282
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=OWN_INIT_5 | %FileCheck %s -check-prefix=OWN_INIT_5
@@ -85,6 +85,8 @@
8585
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=OWN_INIT_8 | %FileCheck %s -check-prefix=OWN_INIT_8
8686
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=OWN_INIT_9 | %FileCheck %s -check-prefix=OWN_INIT_9
8787
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=OWN_INIT_10 | %FileCheck %s -check-prefix=OWN_INIT_10
88+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=OWN_INIT_11 | %FileCheck %s -check-prefix=OWN_INIT_11
89+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=OWN_INIT_12 | %FileCheck %s -check-prefix=OWN_INIT_12
8890

8991
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=OWN_ACCESSOR_1 | %FileCheck %s -check-prefix=OWN_ACCESSOR_1
9092
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=OWN_ACCESSOR_2 | %FileCheck %s -check-prefix=OWN_ACCESSOR_2
@@ -612,6 +614,14 @@ func ownInitTesting() {
612614
// OWN_INIT_10: Begin completions
613615
// OWN_INIT_10-NOT: ownInit10
614616
}
617+
func ownInitTestingParam(ownInit11: Int = #^OWN_INIT_11^#) {
618+
// OWN_INIT_11: Begin completions
619+
// OWN_INIT_11-NOT: Decl[LocalVar]{{.*}}ownInit11
620+
}
621+
func ownInitTestingParamInterp(ownInit12: String = "\(#^OWN_INIT_12^#)") {
622+
// OWN_INIT_12: Begin completions
623+
// OWN_INIT_12-NOT: Decl[LocalVar]{{.*}}ownInit12
624+
}
615625
func ownInitTestingShadow(ownInit7: Int) {
616626
var ownInit7: Int = #^OWN_INIT_7^#
617627
// OWN_INIT_7: Begin completions

0 commit comments

Comments
 (0)