Skip to content

Commit 3e0500d

Browse files
author
Nathan Hawes
committed
[Parse][IDE] Don't drop default argument init exprs containing code completion exprs and type check them for code completion.
Fixes up some tests marked as non-ideal to give the ideal result now too.
1 parent 00994f1 commit 3e0500d

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

lib/IDE/ExprContextAnalysis.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ void swift::ide::typeCheckContextAt(DeclContext *DC, SourceLoc Loc) {
8585
typeCheckPatternBinding(PBD, i);
8686
}
8787
}
88+
} else if (auto *defaultArg = dyn_cast<DefaultArgumentInitializer>(DC)) {
89+
if (auto *AFD = dyn_cast<AbstractFunctionDecl>(defaultArg->getParent())) {
90+
auto *Param = AFD->getParameters()->get(defaultArg->getIndex());
91+
(void*)Param->getTypeCheckedDefaultExpr();
92+
}
8893
}
8994
break;
9095

lib/Parse/ParsePattern.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,10 @@ static ParserStatus parseDefaultArgument(
130130

131131
defaultArgs->HasDefaultArgument = true;
132132

133-
if (initR.hasCodeCompletion())
133+
if (initR.hasCodeCompletion()) {
134+
init = initR.get();
134135
return makeParserCodeCompletionStatus();
136+
}
135137

136138
if (initR.isNull())
137139
return makeParserError();

test/IDE/complete_unresolved_members.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@
109109
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=GENERICPARAM_21 | %FileCheck %s -check-prefix=GENERICPARAM_1
110110

111111
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=DECL_MEMBER_INIT_1 | %FileCheck %s -check-prefix=UNRESOLVED_3
112-
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=DEFAULT_ARG_1 | %FileCheck %s -check-prefix=UNRESOLVED_3_NOTIDEAL
113-
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=DEFAULT_ARG_2 | %FileCheck %s -check-prefix=UNRESOLVED_3_NOTIDEAL
114-
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=DEFAULT_ARG_3 | %FileCheck %s -check-prefix=UNRESOLVED_3_NOTIDEAL
112+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=DEFAULT_ARG_1 | %FileCheck %s -check-prefix=UNRESOLVED_3
113+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=DEFAULT_ARG_2 | %FileCheck %s -check-prefix=UNRESOLVED_3
114+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=DEFAULT_ARG_3 | %FileCheck %s -check-prefix=UNRESOLVED_3
115115

116116
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=TYPEPARAM_IN_CONTEXTTYPE_1 | %FileCheck %s -check-prefix=TYPEPARAM_IN_CONTEXTTYPE_1
117117

0 commit comments

Comments
 (0)