Skip to content

Commit 9d01b59

Browse files
authored
Merge pull request #18270 from rintaro/4.2-ide-complete-printiuo
[4.2][CodeComplete] Use PrintOptionalAsImplicitlyUnwrapped to print IUO
2 parents 8e02cbc + e4c418b commit 9d01b59

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

lib/IDE/CodeCompletion.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2559,16 +2559,17 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
25592559
// What's left is the result type.
25602560
if (ResultType->isVoid()) {
25612561
OS << "Void";
2562-
} else if (!IsImplicitlyCurriedInstanceMethod
2563-
&& FD->getAttrs().hasAttribute<ImplicitlyUnwrappedOptionalAttr>()) {
2562+
} else {
25642563
// As we did with parameters in addParamPatternFromFunction,
25652564
// for regular methods we'll print '!' after implicitly
25662565
// unwrapped optional results.
2567-
auto ObjectType = ResultType->getOptionalObjectType();
2568-
OS << ObjectType->getStringAsComponent();
2569-
OS << "!";
2570-
} else {
2571-
ResultType.print(OS);
2566+
bool IsIUO =
2567+
!IsImplicitlyCurriedInstanceMethod &&
2568+
FD->getAttrs().hasAttribute<ImplicitlyUnwrappedOptionalAttr>();
2569+
2570+
PrintOptions PO;
2571+
PO.PrintOptionalAsImplicitlyUnwrapped = IsIUO;
2572+
ResultType.print(OS, PO);
25722573
}
25732574
}
25742575
Builder.addTypeAnnotation(TypeStr);

lib/IDE/CodeCompletionResultBuilder.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -372,13 +372,8 @@ class CodeCompletionResultBuilder {
372372

373373
PrintOptions PO;
374374
PO.SkipAttributes = true;
375-
std::string TypeName;
376-
if (IsIUO) {
377-
assert(Ty->getOptionalObjectType());
378-
TypeName = Ty->getOptionalObjectType()->getStringAsComponent(PO) + "!";
379-
} else {
380-
TypeName = Ty->getString(PO);
381-
}
375+
PO.PrintOptionalAsImplicitlyUnwrapped = IsIUO;
376+
std::string TypeName = Ty->getString(PO);
382377
addChunkWithText(CodeCompletionString::Chunk::ChunkKind::CallParameterType,
383378
TypeName);
384379

test/IDE/complete_crashes.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,18 +306,28 @@ func test_28188259(x: ((Int) -> Void) -> Void) {
306306
func test_40956846(
307307
arg_40956846_1: inout Int!,
308308
arg_40956846_2: Void!,
309-
arg_40956846_3: (() -> Int)!,
309+
arg_40956846_3: (() -> Int?)!,
310310
arg_40956846_4: inout ((Int) -> Int)!
311311
) {
312312
let y = #^RDAR_40956846^#
313313
}
314314
// RDAR_40956846: Begin completions
315315
// RDAR_40956846-DAG: Decl[LocalVar]/Local: arg_40956846_1[#inout Int!#]; name=arg_40956846_1
316316
// RDAR_40956846-DAG: Decl[LocalVar]/Local: arg_40956846_2[#Void!#]; name=arg_40956846_2
317-
// RDAR_40956846-DAG: Decl[LocalVar]/Local: arg_40956846_3[#(() -> Int)!#]; name=arg_40956846_3
317+
// RDAR_40956846-DAG: Decl[LocalVar]/Local: arg_40956846_3[#(() -> Int?)!#]; name=arg_40956846_3
318318
// RDAR_40956846-DAG: Decl[LocalVar]/Local: arg_40956846_4[#inout ((Int) -> Int)!#]; name=arg_40956846_4
319319
// RDAR_40956846: End completions
320320

321+
// rdar://problem/42443512
322+
// RUN: %target-swift-ide-test -code-completion -code-completion-token=RDAR_42443512 -source-filename=%s | %FileCheck %s -check-prefix=RDAR_42443512
323+
class test_42443512 {
324+
func foo(x: Int!) { }
325+
static func test() {
326+
self.foo#^RDAR_42443512^#
327+
}
328+
}
329+
// RDAR_42443512: Begin completions
330+
321331
// rdar://problem/42452085
322332
// RUN: %target-swift-ide-test -code-completion -code-completion-token=RDAR_42452085_1 -source-filename=%s | %FileCheck %s -check-prefix=RDAR_42452085
323333
// RUN: %target-swift-ide-test -code-completion -code-completion-token=RDAR_42452085_2 -source-filename=%s | %FileCheck %s -check-prefix=RDAR_42452085

0 commit comments

Comments
 (0)