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-11980] Cannot declare open class within public extension w/o warning #54412

Open
swift-ci opened this issue Dec 29, 2019 · 4 comments
Open
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-11980
Radar rdar://problem/58455057
Original Reporter helge (JIRA User)
Type Bug
Environment

Xcode 11, Swift 5.1

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

md5: 6029cb805a9876344a379ec962bbd1dc

Issue Description:

When (ab)using an enum for namespacing purposes, one often wants to declare things in extensions, like so:

public enum BlubStuff {}

public extension BlubStuff {
  open class BlobClass {
  }
}

But this results in an unfortunate:

'open' modifier conflicts with extension's default access of 'public'

There are hacks to workaround that, but in this particular case (`open` class within `public` enum) I think the compiler shouldn't emit a warning.

@beccadax
Copy link
Contributor

beccadax commented Jan 9, 2020

@swift-ci create

@beccadax
Copy link
Contributor

Why? The public keyword on extension is completely optional—removing it gives you exactly the same behavior.

@swift-ci
Copy link
Collaborator Author

Comment by Helge Heß (JIRA)

That's a fair point, I didn't try that. Sounds like a proper workaround.

Though the issue still holds, IMO. There is no reason why you shouldn't be able to declare an open class within a public extension?
So Why? is this disallowed?

@typesanitizer
Copy link

brentdax (JIRA User) I'm also confused as to why the warning exists. If spelling out the public explicitly doesn't make a semantic difference, then why is there a warning when you spell it out explicitly and no warning if you don't?

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
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

3 participants