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-5304] Same name for class and namespace #47879

Open
swift-ci opened this issue Jun 25, 2017 · 5 comments
Open

[SR-5304] Same name for class and namespace #47879

swift-ci opened this issue Jun 25, 2017 · 5 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-5304
Radar None
Original Reporter marian.cerny (JIRA User)
Type Bug
Status Reopened
Resolution
Environment

Xcode 8.3.3
Apple Swift version 3.1 (swiftlang-802.0.53 clang-802.0.42)

Additional Detail from JIRA
Votes 7
Component/s
Labels Bug
Assignee None
Priority Medium

md5: 2b862ecbd903be9a1fa2942328b1de8e

duplicates:

  • SR-4801 Name resolution problem for packages with same-named data types

Issue Description:

I have type Magazine declared in two frameworks.
So I get 'Magazine' is ambiguous for type lookup in this context error.
When I add the correct prefix Book.Magazine, I get 'Magazine' is not a member type of 'Book', because there is a type Book as well.

It's not possible to specify the correct namespace, because the compiler is looking for nested class with the same name instead.

Similar issue: https://forums.developer.apple.com/thread/47421

@swift-ci
Copy link
Collaborator Author

Comment by Marián Černý (JIRA)

This issue is not fixed yet. Tested in Swift 4.2 Xcode 10.0.

Framework A:

public class Magazine {}

Framework B:

public class Magazine {}

Application:

import A

import B

class B {}

class C {

{{ var magazine: B.Magazine?}}

{{}}}

This produces an error: 'Magazine' is not a member type of 'B'

The problem is that there is a type B named the same name as the framework B.

A possible workaround is to create `public typealias B_Magazine = Magazine` inside the framework B and use `B_Magazine` instead of `B.Magazine`.

@swift-ci
Copy link
Collaborator Author

Comment by Marián Černý (JIRA)

Similar problem.

I have a framework Reachability which has a class named Reachability.

I want to create my own wrapper class Reachability inside the App and use the Reachability from the framework inside the class.

Framework Reachability:

class Reachability { … }

Application:

import Reachability

class Reachability {

{{ let reachability = Reachability.Reachability()}}

{{}}}

Same error message: Type 'Reachability' has no member 'Reachability'

Possible workaround is to add `typealias FrameworkReachability = Reachibility` inside the framework (but I don’t want to change the framework) or rename Application’s Reachability for example to MyReachability (which I don’t like, because each module has it’s own namespace and there is no other type Reachability in the app).

A possible solution could be allowing renaming the imports, such as:

import Reachability as FrameworkReachability

@swift-ci
Copy link
Collaborator Author

swift-ci commented Nov 6, 2019

Comment by Artem Loenko (JIRA)

This is still the case with Xcode 11.2 (11.2.1 GM). And we have some issues due to the problem. I think this one is quite important due to the fact that we have the module stability now, and a lot of 3rd party libraries started to adopt BUILD_LIBRARY_FOR_DISTRIBUTION option.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@SimpleApp
Copy link

Any progress on that issue ? It is frankly a very weird limitation. it is not uncommon for modules to contain a public class of the same name as the module..

@enefry
Copy link

enefry commented Dec 20, 2023

+1 same probrom

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.
Projects
None yet
Development

No branches or pull requests

3 participants