[CodeComplete] Fix crasher when completing inout IUO variable

Use `PrintOptionalAsImplicitlyUnwrapped` option.

rdar://problem/40956846
This commit is contained in:
Rintaro Ishizaki
2018-07-11 20:02:56 +09:00
parent 7eb8039eea
commit fb9c65e108
2 changed files with 22 additions and 9 deletions

View File

@@ -1955,17 +1955,13 @@ public:
// lookups is IUO, not Optional as it is for the @optional attribute. // lookups is IUO, not Optional as it is for the @optional attribute.
if (dynamicOrOptional) { if (dynamicOrOptional) {
T = T->getOptionalObjectType(); T = T->getOptionalObjectType();
suffix = "!?"; suffix = "?";
} else {
suffix = "!";
} }
Type ObjectType = T->getReferenceStorageReferent()->getOptionalObjectType(); T = T->getReferenceStorageReferent();
PrintOptions PO;
if (ObjectType->isVoid()) PO.PrintOptionalAsImplicitlyUnwrapped = true;
Builder.addTypeAnnotation("Void" + suffix); Builder.addTypeAnnotation(T.getString(PO) + suffix);
else
Builder.addTypeAnnotation(ObjectType.getStringAsComponent() + suffix);
} }
/// For printing in code completion results, replace archetypes with /// For printing in code completion results, replace archetypes with

View File

@@ -296,3 +296,20 @@ func test_28188259(x: ((Int) -> Void) -> Void) {
// RDAR_28188259-DAG: Pattern/CurrModule: ({#_#})[#Void#]; name=(_) // RDAR_28188259-DAG: Pattern/CurrModule: ({#_#})[#Void#]; name=(_)
// RDAR_28188259-DAG: Keyword[self]/CurrNominal: .self[#(_) -> ()#]; name=self // RDAR_28188259-DAG: Keyword[self]/CurrNominal: .self[#(_) -> ()#]; name=self
// RDAR_28188259: End completions // RDAR_28188259: End completions
// rdar://problem/40956846
// RUN: %target-swift-ide-test -code-completion -code-completion-token=RDAR_40956846 -source-filename=%s | %FileCheck %s -check-prefix=RDAR_40956846
func test_40956846(
arg_40956846_1: inout Int!,
arg_40956846_2: Void!,
arg_40956846_3: (() -> Int)!,
arg_40956846_4: inout ((Int) -> Int)!
) {
let y = #^RDAR_40956846^#
}
// RDAR_40956846: Begin completions
// RDAR_40956846-DAG: Decl[LocalVar]/Local: arg_40956846_1[#inout Int!#]; name=arg_40956846_1
// RDAR_40956846-DAG: Decl[LocalVar]/Local: arg_40956846_2[#Void!#]; name=arg_40956846_2
// RDAR_40956846-DAG: Decl[LocalVar]/Local: arg_40956846_3[#(() -> Int)!#]; name=arg_40956846_3
// RDAR_40956846-DAG: Decl[LocalVar]/Local: arg_40956846_4[#inout ((Int) -> Int)!#]; name=arg_40956846_4
// RDAR_40956846: End completions