[swift-evolution] Proposal: Always flatten the single element tuple
Adrian Zubarev
adrian.zubarev at devandartist.com
Wed Jun 7 07:15:18 CDT 2017
( /* two parameters, not a tuple */ (Int, Int) -> Void).self == (( /* one tuple parameter */ (Int, Int)) -> Void).self // BUG, which SE-0110 should have fixed, but still didn't
Plus inlined:
--
Adrian Zubarev
Sent with Airmail
Am 7. Juni 2017 um 13:53:08, Gwendal Roué (gwendal.roue at gmail.com) schrieb:
func sum1(_ lhs: Int, _ rhs: Int) -> Int { return lhs + rhs }
func sum2(lhs: Int, rhs: Int) -> Int { return lhs + rhs }
func sum3(tuple: (Int, Int)) -> Int { return tuple.0 + tuple.1 }
func sum4(tuple: (lhs: Int, rhs: Int)) -> Int { return tuple.lhs + tuple.rhs }
// two arguments
func f1(_ closure: (Int, Int) -> Int) { closure(1, 2) }
Bug abuse:
f1 { tuple in tuple.0 + tuple.1 }
f1 { (tuple) in tuple.0 + tuple.1 }
f1(sum3)
f1(sum4)
`f2` is no different from `f1`.
Bugs, which should be fixed by `((lhs, rhs)) in`:
// one tuple argument
func f3(_ closure: ((Int, Int)) -> Int) { closure((1, 2)) }
f3 { lhs, rhs in lhs + rhs }
f3 { (lhs, rhs) in lhs + rhs }
Not possible because ultimately the closures have different types.
f3(+)
f3(sum1)
f3(sum2)
Bugs, which should be fixed by `((lhs, rhs)) in`:
// one keyed tuple argument
func f4(_ closure: ((a: Int, b: Int)) -> Int) { closure((a: 1, b: 2)) }
f4 { lhs, rhs in lhs + rhs }
f4 { (lhs, rhs) in lhs + rhs }
Not possible because ultimately the closures have different types.
f4(+)
f4(sum1)
f4(sum2)
Not sure, but I assume this shouldn’t be possible because tuple labels are part of the type and it’s a mismatch like `(lhs: Int, rhs: Int).Type != (a: Int, b: Int).Type`, therefore closures should be of different types as well.
f4(sum4)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170607/bc613fc6/attachment.html>
More information about the swift-evolution
mailing list