Skip to content

Commit 54a99eb

Browse files
authored
Merge pull request swiftlang#26334 from rintaro/ide-completion-errorautoclosure-rdar53507773
[CodeCompletion] Add dyn_cast check to prevent crash
2 parents 911b52f + f3826b8 commit 54a99eb

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/IDE/CodeCompletionResultBuilder.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,11 @@ class CodeCompletionResultBuilder {
377377
// If the parameter is of the type @autoclosure ()->output, then the
378378
// code completion should show the parameter of the output type
379379
// instead of the function type ()->output.
380-
if (isAutoClosure)
381-
Ty = Ty->castTo<FunctionType>()->getResult();
380+
if (isAutoClosure) {
381+
// 'Ty' may be ErrorType.
382+
if (auto funcTy = Ty->getAs<FunctionType>())
383+
Ty = funcTy->getResult();
384+
}
382385

383386
PrintOptions PO;
384387
PO.SkipAttributes = true;

test/IDE/complete_call_arg.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=IMPLICIT_MEMBER_ARRAY_2_SKIPPED | %FileCheck %s -check-prefix=IMPLICIT_MEMBER_SKIPPED
9393

9494
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=ARCHETYPE_GENERIC_1 | %FileCheck %s -check-prefix=ARCHETYPE_GENERIC_1
95+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PARAM_WITH_ERROR_AUTOCLOSURE| %FileCheck %s -check-prefix=PARAM_WITH_ERROR_AUTOCLOSURE
9596

9697
var i1 = 1
9798
var i2 = 2
@@ -738,3 +739,15 @@ func testGenricMethodOnGenericOfArchetype<Wrapped>(value: Wrap<Wrapped>) {
738739
// ARCHETYPE_GENERIC_1: Begin completions
739740
// ARCHETYPE_GENERIC_1: Decl[InstanceMethod]/CurrNominal: ['(']{#(fn): (Wrapped) -> _##(Wrapped) -> _#}[')'][#Wrap<_>#];
740741
}
742+
743+
struct TestHasErrorAutoclosureParam {
744+
func hasErrorAutoclosureParam(value: @autoclosure () -> Value) {
745+
fatalError()
746+
}
747+
func test() {
748+
hasErrorAutoclosureParam(#^PARAM_WITH_ERROR_AUTOCLOSURE^#
749+
// PARAM_WITH_ERROR_AUTOCLOSURE: Begin completions, 1 items
750+
// PARAM_WITH_ERROR_AUTOCLOSURE: Decl[InstanceMethod]/CurrNominal: ['(']{#value: <<error type>>#}[')'][#Void#];
751+
// PARAM_WITH_ERROR_AUTOCLOSURE: End completions
752+
}
753+
}

0 commit comments

Comments
 (0)