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
swift4: Fixes for closure arguments #995
Conversation
@swift-ci test |
I'm not sure I understand what was wrong with the previous syntax. Why did this become a problem? |
There were 2 sets of errors:
Most of the fixes were from fix-its in Xcode |
Just yesterday, the error message "..does not support destructuring" occurred to me in some places in one of my projects. The Xcode fix-it has helped, but I would also like to know why Swift 4 is different in this case than Swift 3. |
Its due to SE-110 https://github.com/apple/swift-evolution/blob/master/proposals/0110-distingish-single-tuple-arg.md |
Is there an alternative to effectively re-declaring the argument all over the place? This can't be the pattern we really want people to use. |
I sent a message to the swift evolution mailing list about this. I think we should have a further discussion before we accept this; it seems like a dramatic reduction in usability of the language in general. |
Yeah thats a good idea. It does seem quite a source breaking change given how much closures are used in general |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An unfortunate result of SE-0110 indeed. If it needs to be committed, just a few stylistic points.
Foundation/Dictionary.swift
Outdated
@@ -18,7 +18,8 @@ extension Dictionary : _ObjectTypeBridgeable { | |||
|
|||
var idx = 0 | |||
|
|||
self.forEach { (keyItem, valueItem) in | |||
self.forEach { (arg) in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stylistic point: this and all subsequent parameter lists in closures don't need the parentheses around arg
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change actually came from the migrator, it may be worth fixing that to not add parentheses as I was taking the fix-its as best practice. Although I'll see what the outcome of the discussion on swift-evolution is before making any changes to this PR
Foundation/NSIndexSet.swift
Outdated
@@ -92,8 +92,8 @@ open class NSIndexSet : NSObject, NSCopying, NSMutableCopying, NSSecureCoding { | |||
|
|||
open func mutableCopy(with zone: NSZone? = nil) -> Any { | |||
let set = NSMutableIndexSet() | |||
enumerateRanges(options: []) { | |||
set.add(in: $0.0) | |||
enumerateRanges(options: []) { (range, stop) in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be range, _
.
Foundation/NSXMLNode.swift
Outdated
@@ -617,8 +617,8 @@ open class XMLNode: NSObject, NSCopying { | |||
if let parentNode = _CFXMLNodeGetParent(parent!) { | |||
let grandparent = XMLNode._objectNodeForNode(parentNode) | |||
let possibleParentNodes = grandparent.filter { $0.name == self.parent?.name } | |||
let count = possibleParentNodes.reduce(0) { | |||
return $0.0 + 1 | |||
let count = possibleParentNodes.reduce(0) { (x, y) in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here too, this could be x, _
.
It seems like most of those are derived from problems in they way functions in the Swift Standard Library are defined, for example |
a92c9c3
to
4168b8a
Compare
- Fix destructuring - Use correct number of arguments in closures
- Fixes "Nested tuple parameter '([Character], JSONReader.Index)' (aka '(Array<Character>, Int)') of function '((([Character], JSONReader.Index)) throws -> _?) throws -> _?' (aka '((Array<Character>, Int) throws -> Optional<_>) throws -> Optional<_>') does not support destructuring"
4fce30c
to
c5114d8
Compare
Rebased. I added an extra commit with some tidy ups of the closure arguments although of course these are subject to personal taste more than anything. @parkera Is this ok for merging now? I noticed most of the SE-110 discussion seems to have ended and any possible changes to the parser will be post swift4 now. |
I don't think that's actually the case, or at least I strongly hope it's not, so I still want to hold off on this. |
Closing for now, this is not needed as the SE-110 change is going to be backed out. See https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20170619/037616.html If any individual closures still generate warnings after the change a new PR can be opened. |
Fix destructuring
Use correct number of arguments in closures
Compatible with swift 3 & 4