Skip to content

Commit b5aa4ab

Browse files
authored
Merge pull request #18217 from rintaro/ide-complete-printiuo
[CodeComplete] Use PrintOptionalAsImplicitlyUnwrapped to print IUO
2 parents 2e45011 + 9e7fa99 commit b5aa4ab

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
@@ -2481,16 +2481,17 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
24812481
// What's left is the result type.
24822482
if (ResultType->isVoid()) {
24832483
OS << "Void";
2484-
} else if (!IsImplicitlyCurriedInstanceMethod
2485-
&& FD->getAttrs().hasAttribute<ImplicitlyUnwrappedOptionalAttr>()) {
2484+
} else {
24862485
// As we did with parameters in addParamPatternFromFunction,
24872486
// for regular methods we'll print '!' after implicitly
24882487
// unwrapped optional results.
2489-
auto ObjectType = ResultType->getOptionalObjectType();
2490-
OS << ObjectType->getStringAsComponent();
2491-
OS << "!";
2492-
} else {
2493-
ResultType.print(OS);
2488+
bool IsIUO =
2489+
!IsImplicitlyCurriedInstanceMethod &&
2490+
FD->getAttrs().hasAttribute<ImplicitlyUnwrappedOptionalAttr>();
2491+
2492+
PrintOptions PO;
2493+
PO.PrintOptionalAsImplicitlyUnwrapped = IsIUO;
2494+
ResultType.print(OS, PO);
24942495
}
24952496
}
24962497
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
@@ -308,18 +308,28 @@ func test_28188259(x: ((Int) -> Void) -> Void) {
308308
func test_40956846(
309309
arg_40956846_1: inout Int!,
310310
arg_40956846_2: Void!,
311-
arg_40956846_3: (() -> Int)!,
311+
arg_40956846_3: (() -> Int?)!,
312312
arg_40956846_4: inout ((Int) -> Int)!
313313
) {
314314
let y = #^RDAR_40956846^#
315315
}
316316
// RDAR_40956846: Begin completions
317317
// RDAR_40956846-DAG: Decl[LocalVar]/Local: arg_40956846_1[#inout Int!#]; name=arg_40956846_1
318318
// RDAR_40956846-DAG: Decl[LocalVar]/Local: arg_40956846_2[#Void!#]; name=arg_40956846_2
319-
// RDAR_40956846-DAG: Decl[LocalVar]/Local: arg_40956846_3[#(() -> Int)!#]; name=arg_40956846_3
319+
// RDAR_40956846-DAG: Decl[LocalVar]/Local: arg_40956846_3[#(() -> Int?)!#]; name=arg_40956846_3
320320
// RDAR_40956846-DAG: Decl[LocalVar]/Local: arg_40956846_4[#inout ((Int) -> Int)!#]; name=arg_40956846_4
321321
// RDAR_40956846: End completions
322322

323+
// rdar://problem/42443512
324+
// RUN: %target-swift-ide-test -code-completion -code-completion-token=RDAR_42443512 -source-filename=%s | %FileCheck %s -check-prefix=RDAR_42443512
325+
class test_42443512 {
326+
func foo(x: Int!) { }
327+
static func test() {
328+
self.foo#^RDAR_42443512^#
329+
}
330+
}
331+
// RDAR_42443512: Begin completions
332+
323333
// rdar://problem/42452085
324334
// RUN: %target-swift-ide-test -code-completion -code-completion-token=RDAR_42452085_1 -source-filename=%s | %FileCheck %s -check-prefix=RDAR_42452085
325335
// 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)