Uploaded image for project: 'Swift'
  1. Swift
  2. SR-2705

Need rule and error on overloads WRT @autoclosure

    XMLWordPrintable

    Details

      Description

      We currently allow the following declarations:

      func autoclosure(f: () -> Int) { }
      func autoclosure(f: @autoclosure () -> Int) { }
      func autoclosure(f: Int) { }
      

      But, this is very troublesome, as how does one go about calling it? We need a consistent ruling here as well as enforcement. The trouble actually cuts both ways:

      func callIt() {
        foo(f: { return 1 }) // <-- error: ambiguous use of 'autoclosure(f:)'
        let foo = autoclosure as (() -> (Int)) -> () // <-- no error, but which one is it?
      }
      

        Attachments

          Activity

            People

            Assignee:
            milseman Michael Ilseman
            Reporter:
            milseman Michael Ilseman
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: