Navigation Menu

Skip to content
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

[SR-15055] Better handle recovery for multiple trailing closures in if let #57382

Open
hamishknight opened this issue Aug 11, 2021 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation

Comments

@hamishknight
Copy link
Collaborator

Previous ID SR-15055
Radar rdar://problem/81799459
Original Reporter @hamishknight
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI
Assignee None
Priority Medium

md5: 46467e1c6f398bdfd6e0866a59f3a95c

Issue Description:

For the following:

func foo(_ fn: () -> Void, a: () -> Void) -> Int? { 0 }

if let i = foo {} a: {} {
  // ...
}

We emit a load of unhelpful diagnostics:

error: consecutive statements on a line must be separated by ';' [statement_same_line_without_semi]
//  if let i = foo {} a: {} {
//                   ^
//                   ;
//  error: labeled block needs 'do' [labeled_block_needs_do]
//  if let i = foo {} a: {} {
//                       ^
//                       do
//  error: consecutive statements on a line must be separated by ';' [statement_same_line_without_semi]
//  if let i = foo {} a: {} {
//                         ^
//                         ;
//  error: top-level statement cannot begin with a closure expression [statement_begins_with_closure]
//  if let i = foo {} a: {} {
//                          ^
//  error: initializer for conditional binding must have Optional type, not '(() -> Void, () -> Void) -> Int?' [condition_optional_element_pattern_not_valid_type]
//  if let i = foo {} a: {} {
//     ^       ~~~
//  error: closure expression is unused [expression_unused_closure]
//  if let i = foo {} a: {} {
//                          ^
//  note: did you mean to use a 'do' statement? [brace_stmt_suggest_do]
//  if let i = foo {} a: {} {
//                          ^
//                          do

We ideally should be able to recover and tell the user to enclose the trailing closures in an argument list, like we do for the single trailing closure case.

@typesanitizer
Copy link

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation
Projects
None yet
Development

No branches or pull requests

2 participants