Skip to content

[CodeComplete] Fix crasher when completing inout IUO variable #17926

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions lib/IDE/CodeCompletion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1955,17 +1955,13 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
// lookups is IUO, not Optional as it is for the @optional attribute.
if (dynamicOrOptional) {
T = T->getOptionalObjectType();
suffix = "!?";
} else {
suffix = "!";
suffix = "?";
}

Type ObjectType = T->getReferenceStorageReferent()->getOptionalObjectType();

if (ObjectType->isVoid())
Builder.addTypeAnnotation("Void" + suffix);
else
Builder.addTypeAnnotation(ObjectType.getStringAsComponent() + suffix);
T = T->getReferenceStorageReferent();
PrintOptions PO;
PO.PrintOptionalAsImplicitlyUnwrapped = true;
Builder.addTypeAnnotation(T.getString(PO) + suffix);
}

/// For printing in code completion results, replace archetypes with
Expand Down
17 changes: 17 additions & 0 deletions test/IDE/complete_crashes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -296,3 +296,20 @@ func test_28188259(x: ((Int) -> Void) -> Void) {
// RDAR_28188259-DAG: Pattern/CurrModule: ({#_#})[#Void#]; name=(_)
// RDAR_28188259-DAG: Keyword[self]/CurrNominal: .self[#(_) -> ()#]; name=self
// 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
Copy link
Member Author

@rintaro rintaro Jul 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rudkx I already have a test case for (() -> Int)!.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I didn't paste in the right example - I meant an inout variant of that, like inout (() -> Int)!.

// RDAR_40956846-DAG: Decl[LocalVar]/Local: arg_40956846_4[#inout ((Int) -> Int)!#]; name=arg_40956846_4
// RDAR_40956846: End completions