Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-7909] Module type namespace collision #50444

Closed
swift-ci opened this issue Jun 7, 2018 · 1 comment
Closed

[SR-7909] Module type namespace collision #50444

swift-ci opened this issue Jun 7, 2018 · 1 comment
Labels
compiler The Swift compiler in itself improvement

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Jun 7, 2018

Previous ID SR-7909
Radar None
Original Reporter parski (JIRA User)
Type Improvement
Status Resolved
Resolution Duplicate

Attachment: Download

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Improvement
Assignee None
Priority Medium

md5: e100af8449098240757d16638ad52712

duplicates:

  • SR-898 Unresolvable "ambiguous for type lookup" error when using multiple modules

Issue 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.

@swift-ci
Copy link
Collaborator Author

Comment by Pär Strindevall (JIRA)

I've added a playground to demonstrate the issue.

Maybe a pound expression can be used to explicitly use the module? Like so:

#module(XCTest).XCTFail()

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler The Swift compiler in itself improvement
Projects
None yet
Development

No branches or pull requests

1 participant