Skip to content

SE-0025: Allow public members inside internal types. #3404

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

Merged
merged 1 commit into from
Jul 11, 2016

Conversation

jrose-apple
Copy link
Contributor

(and any other member with higher access control than its enclosing type)

There's no effect, but it is now considered legal and the compiler will no longer warn about it. This allows an API author to prototype their API with proper access levels and still limit the top-level type.

If the new getEffectiveAccess computation turns out to be expensive, we can cache the result.

Note that the compiler will still warn when putting a public member inside an extension explicitly marked internal, because the extended type could be public and then including a public member would be valid. It is also still an error to put a public member inside a constrained extension of an internal type, though I think this one is safe to relax later.

Progress on SE-0025 (private and fileprivate)


Before merging this pull request to apple/swift repository:

  • Test pull request on Swift continuous integration.

Triggering Swift CI

The swift-ci is triggered by writing a comment on this PR addressed to the GitHub user @swift-ci. Different tests will run depending on the specific comment that you use. The currently available comments are:

Smoke Testing

Platform Comment
All supported platforms @swift-ci Please smoke test
All supported platforms @swift-ci Please smoke test and merge
OS X platform @swift-ci Please smoke test OS X platform
Linux platform @swift-ci Please smoke test Linux platform

Validation Testing

Platform Comment
All supported platforms @swift-ci Please test
All supported platforms @swift-ci Please test and merge
OS X platform @swift-ci Please test OS X platform
OS X platform @swift-ci Please benchmark
Linux platform @swift-ci Please test Linux platform

Lint Testing

Language Comment
Python @swift-ci Please Python lint

Note: Only members of the Apple organization can trigger swift-ci.

@jrose-apple
Copy link
Contributor Author

@swift-ci Please test

@jrose-apple
Copy link
Contributor Author

@CodaFi, @slavapestov, mind reviewing?

} else if (auto enclosingExt = dyn_cast<ExtensionDecl>(getDeclContext())) {
// Just check the base type. If it's a constrained extension, Sema should
// have already enforced access more strictly.
if (auto nominal = enclosingExt->getExtendedType()->getAnyNominal()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enclosingExt->getExtendedType() should be conditionally accessed as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yyyep, apparently so. Fixed.

@jrose-apple jrose-apple force-pushed the allow-broad-access branch from 96cdef2 to 59af066 Compare July 8, 2016 01:14
(and any other member with higher access control than its enclosing type)

There's no effect, but it is now considered legal and the compiler will
no longer warn about it. This allows an API author to prototype their
API with proper access levels and still limit the top-level type.

If the new getEffectiveAccess computation turns out to be expensive, we
can cache the result.

Note that the compiler will still warn when putting a public member
inside an extension explicitly marked internal, because the extended
type could be public and then including a public member would be valid.
It is also still an error to put a public member inside a constrained
extension of an internal type, though I think this one is safe to
relax later.

Progress on SE-0025 ('private' and 'fileprivate')
@jrose-apple
Copy link
Contributor Author

@swift-ci Please test

@slavapestov
Copy link
Contributor

Looks reasonable. I recall seeing some radars where someone reported seeing a diagnostic about how something (an extension?) could not be public, and then after removing the public keyword, another diagnostic complained it cannot be private. I don't remember the details though, but maybe if you know, it could be worth cleaning that up as well.

@jrose-apple
Copy link
Contributor Author

@swift-ci Please smoke test

@jrose-apple jrose-apple merged commit 306edda into swiftlang:master Jul 11, 2016
@jrose-apple jrose-apple deleted the allow-broad-access branch July 11, 2016 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants