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

Compound name syntax for functions with no params

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Medium
    • Resolution: Unresolved
    • Component/s: Compiler
    • Labels:

      Description

      The "compound name" of a function can be used to resolve ambiguities with argument labels, e.g. foo(x:) or foo(_:). However, there's no such shortcut to specify an overload that has no arguments. A workaround is to use its type with as:

      import Foundation
      class C: NSObject {
          func foo() {}
          func foo(x: Int) {}
      }
      
      #selector(C.foo)  // error: ambiguous use of 'foo'
      #selector(C.foo(x:))  // resolve ambiguity with compound name
      #selector(C.foo as (C) -> () -> ())  // resolve ambiguity by specifying type
      

      But it'd be nice to have some way of doing this without specifying the type. Perhaps foo(_) (for symmetry with foo(_:))?

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                jtbandes Jacob Bandes-Storch
              • Votes:
                0 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated: