Skip to content

Commit 456952e

Browse files
authored
Merge pull request #17926 from rintaro/ide-complete-rdar40956846
[CodeComplete] Fix crasher when completing inout IUO variable
2 parents 0155720 + fb9c65e commit 456952e

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

lib/IDE/CodeCompletion.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1955,17 +1955,13 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
19551955
// lookups is IUO, not Optional as it is for the @optional attribute.
19561956
if (dynamicOrOptional) {
19571957
T = T->getOptionalObjectType();
1958-
suffix = "!?";
1959-
} else {
1960-
suffix = "!";
1958+
suffix = "?";
19611959
}
19621960

1963-
Type ObjectType = T->getReferenceStorageReferent()->getOptionalObjectType();
1964-
1965-
if (ObjectType->isVoid())
1966-
Builder.addTypeAnnotation("Void" + suffix);
1967-
else
1968-
Builder.addTypeAnnotation(ObjectType.getStringAsComponent() + suffix);
1961+
T = T->getReferenceStorageReferent();
1962+
PrintOptions PO;
1963+
PO.PrintOptionalAsImplicitlyUnwrapped = true;
1964+
Builder.addTypeAnnotation(T.getString(PO) + suffix);
19691965
}
19701966

19711967
/// For printing in code completion results, replace archetypes with

test/IDE/complete_crashes.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,3 +296,20 @@ func test_28188259(x: ((Int) -> Void) -> Void) {
296296
// RDAR_28188259-DAG: Pattern/CurrModule: ({#_#})[#Void#]; name=(_)
297297
// RDAR_28188259-DAG: Keyword[self]/CurrNominal: .self[#(_) -> ()#]; name=self
298298
// RDAR_28188259: End completions
299+
300+
// rdar://problem/40956846
301+
// RUN: %target-swift-ide-test -code-completion -code-completion-token=RDAR_40956846 -source-filename=%s | %FileCheck %s -check-prefix=RDAR_40956846
302+
func test_40956846(
303+
arg_40956846_1: inout Int!,
304+
arg_40956846_2: Void!,
305+
arg_40956846_3: (() -> Int)!,
306+
arg_40956846_4: inout ((Int) -> Int)!
307+
) {
308+
let y = #^RDAR_40956846^#
309+
}
310+
// RDAR_40956846: Begin completions
311+
// RDAR_40956846-DAG: Decl[LocalVar]/Local: arg_40956846_1[#inout Int!#]; name=arg_40956846_1
312+
// RDAR_40956846-DAG: Decl[LocalVar]/Local: arg_40956846_2[#Void!#]; name=arg_40956846_2
313+
// RDAR_40956846-DAG: Decl[LocalVar]/Local: arg_40956846_3[#(() -> Int)!#]; name=arg_40956846_3
314+
// RDAR_40956846-DAG: Decl[LocalVar]/Local: arg_40956846_4[#inout ((Int) -> Int)!#]; name=arg_40956846_4
315+
// RDAR_40956846: End completions

0 commit comments

Comments
 (0)