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

Module type namespace collision

    XMLWordPrintable

    Details

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

      Description

      Background

      When using a global function defined in a module that shares the name with a global function defined in another it is possible to use the module name to solve the ambiguity.

      For example, in Apple's Foundation contains the global function NSLocalizedString(). Should there be another module containing a global function with the same name the Foundation function can be invoked like so:

      Foundation.NSLocalizedString()

      Problem

      If an imported module has a type that shares it's name there is no way to specify the module's global function using Swift.

      For example, XCTest is the name of a module but it also contains a class with the same name. The module has several global functions but attempting to invoke them using it's namespace results in Swift trying to access them from the XCTest class.

       

      // Invokes the NSLocalizedString function from the Foundation module
      Foundation.NSLocalizedString("key", comment: "comment")
      
      // Will not compile as the class XCTest does not contain the XCTFail function
      XCTest.XCTFail("reason of failure")

       

      I would like to be able to somehow specify a global entity within a module namespace in the case that a module shares it's name with one of it's contained types.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              parski Pär Strindevall
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: