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-7532] "Class should not be declared public..." shouldn't apply to type aliases for public types #50074

Closed
AnthonyLatsis opened this issue Apr 25, 2018 · 5 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@AnthonyLatsis
Copy link
Collaborator

Previous ID SR-7532
Radar None
Original Reporter @AnthonyLatsis
Type Bug
Status Resolved
Resolution Invalid
Environment

Xcode 9.3 (9E145), 9.4 beta

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

md5: d0e9140caa531f2e87bfe28af94db6f7

relates to:

  • SR-7622 Non-public typealias should be exported as public equivalent when possible

Issue Description:

This is, as I recently discovered, correct behavior. However, it is not logical to apply this warning to type aliases for >=public types, since they can be exposed as the canonical type for the consumer.

internal typealias T = Bool

public class Foo<U> {}

public class BoolFoo: Foo<T> {} // Class should not be declared public because its superclass is internal
@belkadan
Copy link
Contributor

belkadan commented May 1, 2018

This is correct behavior too. Being public means that your declaration is shown to clients in other modules. They have to be able to see all the types involved!

@belkadan
Copy link
Contributor

belkadan commented May 1, 2018

(The compiler has to assume the typealias is meaningful; it won't just blindly throw it away.)

@AnthonyLatsis
Copy link
Collaborator Author

@belkadan Does meaningful here mean "the typealias can be substituted with the type it refers to without violating the access level of that type"?

I still don't quite get why an inaccessible typealias can't be thrown away for the consumer in favor of the type it refers to if that type is accessible for the user.
For instance, the developer wants to use an alias for a complex public type within the module for readability, but doesn't want to expose that alias to the consumer. I know this isn't a strong use case, but even so, does it really make sense for functions and types to become inaccessible just because a typealias in their signature is itself inaccessible?

@belkadan
Copy link
Contributor

belkadan commented May 3, 2018

There's no way for the compiler to tell the difference between "I'm using this for my convenience" and "I'm trying to show this to users but forgot it was internal". Right now there's a consistent rule, if restrictive. If you're interested in changing this, bring it up on the Swift Evolution forums.

@AnthonyLatsis
Copy link
Collaborator Author

How could I miss that...Of course, the user might want to do the opposite. Thank you.

@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
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

2 participants