[swift-evolution] [Proposal] Revising access modifiers on extensions
Adrian Zubarev
adrian.zubarev at devandartist.com
Mon Jun 27 15:00:20 CDT 2016
I still have no idea why you want to make this change, other than “putting an access modifier on an extension is different from putting an access modifier on a type”. Are you trying to hide protocol conformances that would be otherwise public?
In my proposal I cannot hide a public protocol conformance. Its not possible with normal types and it shouldn’t be possible with extensions as well. (Correct me if I’m wrong.) I really want the same access control behavior with extensions like whit classes, enums and structs. For new Swift developers such consistency would be great, because they won’t need to learn another access control behavior (second one goes to protocols).
As I showed in my proposal right now its possible to create three different version of public protocol default implementation:
public protocol A {
func foo()
}
extension A {
public func foo() {}
}
public extension A {
func foo() {}
}
public extension A {
public func foo() {}
}
If it was a type and I wanted foo to be visible I’d do this:
public struct B {
public func foo() {}
}
With the proposed content access control we’d have only one way for public protocol default implementation:
public extension A {
public func foo() {}
}
Yet it fells strange when there is protocol conformance that we’re not allowed to use access modifier anymore for our extension bag.
// Assume `A` has no default implementation
// Extension must retain `public` because B is `public` and `A` as well
// Explicitly public which is crystal clear
public extension B : A {
// foo must retain `public`
public func foo()
// custom member - implicitly internal - like on classes enums structs
func member() {}
}
Some rules from the proposal:
Access modifier on extensions should respect the modifier of the extended type and the protocol to which it should conform.
Public protocol:
public type + public protocol = public extension
internal type + public protocol = internal extension
private type + public protocol = private extension
Internal protocol:
public type + internal protocol = public extension or internal extension
internal type + internal protocol = internal extension
private type + internal protocol = private extension
Private protocol:
public type + private protocol = public extension or internal extension or private extension
internal type + private protocol = internal extension or private extension
private type + private protocol = private extension
Multiple protocol conformance is decided analogously by using the highest access modifier from all protocols + the access level of the extended type.
That has much greater consequences and a much stronger domino effect than what you’ve discussed here.
Could you explain this a little more? Maybe I’m to blind to see what else could break this my proposal.
--
Adrian Zubarev
Sent with Airmail
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160627/f864aef7/attachment.html>
More information about the swift-evolution
mailing list