> 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> 

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to