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-4738] Can not decompose nested tuple in closure arguments #47315

Closed
palimondo mannequin opened this issue Apr 29, 2017 · 7 comments
Closed

[SR-4738] Can not decompose nested tuple in closure arguments #47315

palimondo mannequin opened this issue Apr 29, 2017 · 7 comments
Assignees
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 parser Area → compiler: The legacy C++ parser

Comments

@palimondo
Copy link
Mannequin

palimondo mannequin commented Apr 29, 2017

Previous ID SR-4738
Radar None
Original Reporter @palimondo
Type Bug
Status Resolved
Resolution Done
Environment

swift 3.1

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

md5: d4c1de7db38fa542753c5b163d9d9f93

relates to:

  • SR-1620 Destructuring nested tuples in closure arguments
  • SR-4745 for (index, (a, b)) in dict.enumerated() produces an error
  • SR-2135 Multiple Tuple Parameters to a Closure cannot be Decomposed in the Parameter List

Issue Description:

Nested tuples can not be decomposed in argument list for closure:

let t = (1, (2, 3))
let (a, (b, c)) = t // works

[t].map { (x, (y, z)) -> Int in x + y + z }
// error: unnamed parameters must be written with the empty name '_'

cc @rudkx, @belkadan

@rudkx
Copy link
Member

rudkx commented May 2, 2017

As mentioned in SR-2135, this isn't really intended to work because we don't support general destructuring in parameter lists. There was special-case behavior that only worked for a single tuple argument but that is going away in -swift-version 4.

This on the other hand is a close alternative that explicitly uses destructuring on the single tuple argument:

[t].map { (tuple) -> Int in
  let (x, (y, z)) = tuple
  return x + y + z
}

@rudkx
Copy link
Member

rudkx commented May 2, 2017

Again I'll note the bad diagnostic. We would ideally do better here.

@palimondo
Copy link
Mannequin Author

palimondo mannequin commented May 10, 2017

This issue is possibly a duplicate of SR-1620, but that one is unassigned and has no recent comments...

@xedin
Copy link
Member

xedin commented May 10, 2017

Thanks, Pavol![]( I am in the process of merging one of the related patches to 4.0 branch, once that happens I am going to go through all of the issues and see which ones have been resolved by it. Stay tuned)

@palimondo
Copy link
Mannequin Author

palimondo mannequin commented May 10, 2017

Pavel, can you provide PR #?
Also, is this just improvement to diagnostic messages or a fix for general tuple decomposition?

If the first… what is the justification for having the single tuple decomposition in the for-in loop - the same that was removed from closure arguments?

@xedin
Copy link
Member

xedin commented May 10, 2017

It's #9425 and it's improvement to diagnostic yes.

If the first… what is the justification for having the single tuple decomposition in the for-in loop - the same that was removed from closure arguments?

I'm actually not quiet sure what is the motivation behind that but maybe @slavapestov can shed some light?

@xedin
Copy link
Member

xedin commented May 10, 2017

PR 9425 has landed to 4.0 branch so here is the diagnostic example for the description is going to produce:

<REPL Input>:1:15: error: closure tuple parameter does not support destructuring
[t].map { (x, (y, z)) -> Int in x + y + z }
              ^~~~~~
              arg1              let (y, z) = arg1;

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
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 parser Area → compiler: The legacy C++ parser
Projects
None yet
Development

No branches or pull requests

2 participants