[swift-evolution] [Pitch] Extending [at]autoclosure

Ben Rimmington me at benrimmington.com
Sun Jun 25 02:03:04 CDT 2017


> On 24 Jun 2017, at 17:10, Adrian Zubarev wrote:
> 
> 2. Make @autoclosure only wrap when necessary:
> 
> func bar(_ test: @autoclosure () -> Int) {
>     print(test())
> }
> 
> let test = { 42 }
> 
> // function produces expected type 'Int'; did you mean to call it with '()'?
> bar(test)

Note that you can forward an autoclosure to another function:
Welcome to Apple Swift version 3.1 (swiftlang-802.0.53 clang-802.0.42).
  1> func foo(_ test: @autoclosure () -> Int) {
  2.     print(#function, test())
  3. }
  4. 
  5. func bar(_ test: @autoclosure () -> Int) {
  6.     foo(test)
  7. }
  8. 
  9. func baz(_ test: @autoclosure () -> Int) {
 10.     bar(test)
 11. }
 12. 
 13. baz(42)
foo 42
 14> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170625/8827b687/attachment.html>


More information about the swift-evolution mailing list