On 13 October 2017 at 22:50, Jean-Daniel <[email protected]> wrote:
I mean:
>
> func foo() -> Int { … }
>
> func bar(callback: () -> discardable Int) { … }
>
> bar(foo) // does it warns ?
> bar({ 3 }) // does it warns ? If it does, how to avoid it ?
>
thanks.
>>> And allowing it in signature but not in lambda would be confusing.
not any more confusing than it is now (allowing @discardableResult before
function name and not allowing it before closure parameters).
but, if to fix that, than could be this (orthogonal to whether it is
"@discardableResult" or "discardable"):
func foo() -> Int {}
func bar(_ callback: () -> discardable Int) {}
bar(foo) // error, type mismatch
bar({ 3 }) // error, type mismatch
bar({ () -> discardable Int in 3 }) // ok, types matched
- and -
func poo() -> discardable Int {}
func baz(_ callback: () -> Int) {}
baz(poo) // ok, types compatible
baz({ 3 }) // ok, types matched
baz({ () -> discardable Int in 3 }) // ok, types compatible
Mike
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution