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-2135] Multiple Tuple Parameters to a Closure cannot be Decomposed in the Parameter List #44743

Open
swift-ci opened this issue Jul 21, 2016 · 3 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-2135
Radar None
Original Reporter fabb (JIRA User)
Type Bug
Environment

Xcode 8 beta 3

Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels Bug, TypeChecker
Assignee @xedin
Priority Medium

md5: 5e4da572fd5a13ece72e71969fed1248

relates to:

  • SR-1620 Destructuring nested tuples in closure arguments
  • SR-1261 Swift incorrectly identifies passing a tuple to a function as a tuple splat
  • SR-2008 Implement SE-0110: Distinguish between single-tuple and multiple-argument function types
  • SR-4738 Can not decompose nested tuple in closure arguments

Issue Description:

// example 1
let d: [Int: String] = [1:"1", 0:"0"]
let e = d.sorted(isOrderedBefore: { (k1, v1), (k2, v2) in k1 < k2 }) // does not compile

// example 2
let g: [(Int, String)] = [(1, "1"), (0, "0")]
let h = g.sorted(isOrderedBefore: { (k1, v1), (k2, v2) in k1 < k2 }) // does not compile

// simplified example 3
let c: ((Int, String), (Int, String)) -> Void = { (key1, value1), (key2, value2) in } // does not compile
@swift-ci
Copy link
Collaborator Author

@palimondo
Copy link
Mannequin

palimondo mannequin commented Apr 29, 2017

The reported error: consecutive statements on a line must be separated by ‘;'

cc @rudkx, @belkadan

@rudkx
Copy link
Member

rudkx commented May 2, 2017

We don't really support destructuring tuples in parameter lists, although it sort of seems like we do in some cases.

The right thing to do here is declare the tuple arguments and reference the elements:

let e = d.sorted(by: { (lhs: (Int, String), rhs: (Int, String)) in lhs.0 < rhs.0 })

or

let e = d.sorted(by: { (lhs, rhs) in lhs.0 < rhs.0 })

or

let e = d.sorted(by: { (lhs, rhs) in
    let (k1, _) = lhs
    let (k2, _) = rhs
    return k1 < k2
  })

Having said that, the diagnostic here is really not helpful.

@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 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

2 participants