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

Methods on self should not block unambiguous calls to free functions

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Duplicate
    • Component/s: Compiler
    • Labels:

      Description

      If you have a method on self with the same basename, the compiler will refuse to let you call free functions without full qualification, even when the call is unambiguous due to an argument labels, arity, types etc. This makes for a frustrating user experience, and requires workarounds for source compatibility when introducing methods that shadow existing functions.

      Most prominent case is calling max passing in two arguments inside an extension on a Sequence (which has a no-argument max function). Even though it's not ambiguous, you have to write Swift.max which is ugly and hard for new users to discover.

      func foo(i: Int) { }
      
      struct S {
        func foo() { }
        func bar() {
          // error: use of 'foo' refers to instance method 'foo()' rather than global function 'foo(i:)'
          foo(i: 1)
        }
      }
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                airspeedswift Ben Cohen
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: