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

File-level function with the same name as instance function not picked up by compiler

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Medium
    • Resolution: Unresolved
    • Component/s: Compiler
    • Labels:
      None
    • Environment:

      OS X 10.11.5, Xcode 8b1

      Description

      I'm attaching a playground file that demonstrates the issue:

      Have a function at the file-level:

      private func _validateAccountName(name: String, existingAccounts: [Account]) -> Bool {
          // Logic goes here...
      }
      

      which includes a name-checking logic which you want to be shared among several components in the file.

      Then create class that has the following method:

      class MyController {
          private func _validateAccountName(name: String) -> Bool {
              let accounts = ...
              return _validateAccountName(name, existingAccounts: accounts)
          }
      }
      

      The compiler complains that there's an extra argument existingAccounts within the call. There is hence no way to address the function outside of the controller class without renaming it. The compiler should consider it as an overload candidate as well. Since self. is not explicitely mentioned, the compiler should use the file-level function.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                charlieMonroe Charlie Monroe
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated: