You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SR-1528 Swift compiler requires closures without parameter lists to reference all arguments
relates to:
SR-586 $0 captures all closure argument as single tuple when no larger-numbed $N used
Issue Description:
Closures with arguments should allow using only some or none of those arguments. However, the current state of things requires using at least the final argument, else error.
Example:
func foo(_ closure:(Int,Int,Int)->Void) {
closure(1,2,3)
}
foo { } // ERROR: "expects 3 arguments, which cannot be implicitly ignored"
foo { print($0) } // ERROR: "expects 3 arguments, but 1 was used"
foo { print($1) } // ERROR: "expects 3 arguments, but 2 were used" Huh? There was only 1 used.
foo { print($0,$1) } // ERROR: "expects 3 arguments, but 2 were used"
foo { print($0,$1,$2) } // OK
foo { print($2) } // OK
// ^^^ Though it might as well say "expects 3 arguments, but 1 was used"
I am suggesting that all of the above scenarios should work without error.
Here is a more practical example, where a second argument is an index which may or may not be used (since it's optional it is intentionally the last arg):
func each(_ closure: (T, Int) -> Void) { .. }
// should be able to call using first parameter only:
foo.each { $0.doSomething } // ERROR: "expects 2 arguments, but 1 was used"
Environment
Swift 4 via Xcode 9.2
Additional Detail from JIRA
md5: f98cf2e06ba3ef8b4259e0417cd0c208
duplicates:
relates to:
Issue Description:
Closures with arguments should allow using only some or none of those arguments. However, the current state of things requires using at least the final argument, else error.
Example:
I am suggesting that all of the above scenarios should work without error.
Here is a more practical example, where a second argument is an index which may or may not be used (since it's optional it is intentionally the last arg):
See also: https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160118/007095.html
The text was updated successfully, but these errors were encountered: