<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div><br><br>Sent from my iPad</div><div><br>On Feb 11, 2017, at 12:44 PM, Xiaodi Wu &lt;<a href="mailto:xiaodi.wu@gmail.com">xiaodi.wu@gmail.com</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><div dir="ltr">On Sat, Feb 11, 2017 at 12:42 PM, Matthew Johnson via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
Sent from my iPad<br>
<span class=""><br>
&gt; On Feb 11, 2017, at 7:22 AM, Rien &lt;<a href="mailto:Rien@Balancingrock.nl">Rien@Balancingrock.nl</a>&gt; wrote:<br>
&gt;<br>
&gt; I admit that I have not followed all of this discussion, but as far as I see, we could equally well do this by calling “not-open” enum’s “final”.<br>
&gt; It seems like a better fit to me.<br>
<br>
</span>That is actually not a very good fit at all.&nbsp; `final` means a class cannot have any subclasses.&nbsp; If we applied it to enums I think the closest parallel would be an enum with no cases.&nbsp; But this makes the enum uninhabited so it is not just like `final class`, but actually more like `abstract final class`.<br></blockquote><div><br></div><div>Well, you _could_ move `final` to the cases themselves, and it would mean the right thing: `enum Foo { final case bar, baz }`.</div></div></div></div></div></blockquote><div><br></div>I don't quite follow this. &nbsp;In order for `final` to mean something when applied to a kind of entity it should also be meaningful to non-final entities of that same kind. &nbsp;What would a non-final case be?<div><br><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5"><br>
&gt;<br>
&gt; Regards,<br>
&gt; Rien<br>
&gt;<br>
&gt; Site: <a href="http://balancingrock.nl" rel="noreferrer" target="_blank">http://balancingrock.nl</a><br>
&gt; Blog: <a href="http://swiftrien.blogspot.com" rel="noreferrer" target="_blank">http://swiftrien.blogspot.com</a><br>
&gt; Github: <a href="http://github.com/Balancingrock" rel="noreferrer" target="_blank">http://github.com/<wbr>Balancingrock</a><br>
&gt; Project: <a href="http://swiftfire.nl" rel="noreferrer" target="_blank">http://swiftfire.nl</a><br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;&gt; On 11 Feb 2017, at 14:07, Matthew Johnson via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; Sent from my iPad<br>
&gt;&gt;<br>
&gt;&gt;&gt; On Feb 11, 2017, at 4:25 AM, Adrian Zubarev via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; I’m probably better describing things with some bikeshedding code, but feel free to criticize it as much as you’d like.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; //===========--------- Module A ---------===========//<br>
&gt;&gt;&gt; @closed public enum A {<br>
&gt;&gt;&gt;&nbsp; &nbsp; case a<br>
&gt;&gt;&gt; }<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; extension A {<br>
&gt;&gt;&gt;&nbsp; &nbsp; case aa // error, because enum is closed<br>
&gt;&gt;&gt; }<br>
&gt;&gt;&gt;<br>
&gt;&gt; This is an error because you can't add cases in an extension.&nbsp; I imagine this is how cases would be added outside the module if we allow `open enum` in the future.&nbsp; But whether or not this is allowed *within* the module is a separate question that is orthogonal to `closed` and `open`.<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; public func foo(a: A) {<br>
&gt;&gt;&gt;&nbsp; &nbsp; switch a {<br>
&gt;&gt;&gt;&nbsp; &nbsp; case .a:<br>
&gt;&gt;&gt;&nbsp; &nbsp; &nbsp; &nbsp; print("done")<br>
&gt;&gt;&gt;&nbsp; &nbsp; }<br>
&gt;&gt;&gt; }<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; public enum B {<br>
&gt;&gt;&gt;&nbsp; &nbsp; case b<br>
&gt;&gt;&gt; }<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; extension B {<br>
&gt;&gt;&gt;&nbsp; &nbsp; case bb // fine, because not-closed enums are extensible<br>
&gt;&gt;&gt; }<br>
&gt;&gt;&gt;<br>
&gt;&gt; As noted above, whether this is allowed or not *within* the module is orthogonal to `closed`.&nbsp; *Outside* the module it would only be possible for enum declared `open` (if we add this feature in the future).<br>
&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; public func bar(b: B) {<br>
&gt;&gt;&gt;&nbsp; &nbsp; switch b {<br>
&gt;&gt;&gt;&nbsp; &nbsp; case .b:<br>
&gt;&gt;&gt;&nbsp; &nbsp; &nbsp; &nbsp; print("b")<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;&nbsp; &nbsp; default: // always needed<br>
&gt;&gt;&gt;&nbsp; &nbsp; &nbsp; &nbsp; print("some other case")<br>
&gt;&gt;&gt;&nbsp; &nbsp; }<br>
&gt;&gt;&gt; }<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; // Sub-enum relationships<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; // Possible even the enum A is closed, because `@closed` only<br>
&gt;&gt;&gt; // closes the extensibility of an enum<br>
&gt;&gt;&gt; enum SubA : A {<br>
&gt;&gt;&gt;&nbsp; &nbsp; case aa<br>
&gt;&gt;&gt; }<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt; Now you're talking about value subtypes.&nbsp; That is orthogonal.&nbsp; Also, this syntax already has a meaning (the raw value of the enum is A) so we wouldn't be able to use it the way you are intending here.&nbsp; Finally, it is misleading syntax because what you mean here is "A is a subtype of SubA" which is exactly the opposite of what the syntax implies.<br>
&gt;&gt;<br>
&gt;&gt; All values of A are valid values of SubA, but SubA has values that are not valid values of A.<br>
&gt;&gt;<br>
&gt;&gt;&gt; // The following enum can have a sub-enum in the clients module<br>
&gt;&gt;&gt; open enum C {<br>
&gt;&gt;&gt;&nbsp; &nbsp; case c<br>
&gt;&gt;&gt; }<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; public func cool(c: C) {<br>
&gt;&gt;&gt;&nbsp; &nbsp; switch c {<br>
&gt;&gt;&gt;&nbsp; &nbsp; case .c:<br>
&gt;&gt;&gt;&nbsp; &nbsp; &nbsp; &nbsp; print("c")<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;&nbsp; &nbsp; default: // always needed<br>
&gt;&gt;&gt;&nbsp; &nbsp; &nbsp; &nbsp; print("some other case")<br>
&gt;&gt;&gt;&nbsp; &nbsp; }<br>
&gt;&gt;&gt; }<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; @closed open enum D {<br>
&gt;&gt;&gt;&nbsp; &nbsp; case d<br>
&gt;&gt;&gt; }<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; public func doo(d: D) {<br>
&gt;&gt;&gt;&nbsp; &nbsp; switch b {<br>
&gt;&gt;&gt;&nbsp; &nbsp; case .b:<br>
&gt;&gt;&gt;&nbsp; &nbsp; &nbsp; &nbsp; print("b")<br>
&gt;&gt;&gt;&nbsp; &nbsp; }<br>
&gt;&gt;&gt; }<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; // The enum case is always known at any point, no matter<br>
&gt;&gt;&gt; // where the instance comes from, right?<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; let subA = SubA.aa<br>
&gt;&gt;&gt; let otherSubA = SubA.a // Inherited case<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; let a: A = subA&nbsp; &nbsp; &nbsp; &nbsp; // error, downgrade the sub-enum to A first<br>
&gt;&gt;&gt; let a: A = otherSubA&nbsp; &nbsp;// okay<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; foo(a: subA)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// error, downgrade the sub-enum to A first<br>
&gt;&gt;&gt; foo(a: otherSubA)&nbsp; &nbsp; &nbsp; // okay<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; //===========--------- Module B ---------===========//<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; // Totally fine<br>
&gt;&gt;&gt; switch A.a {<br>
&gt;&gt;&gt; case .a:<br>
&gt;&gt;&gt;&nbsp; &nbsp; print("done")<br>
&gt;&gt;&gt; }<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; extension A {<br>
&gt;&gt;&gt;&nbsp; &nbsp; case aa // not allowed because the enum is closed<br>
&gt;&gt;&gt; }<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; extension B {<br>
&gt;&gt;&gt;&nbsp; &nbsp; case bbb<br>
&gt;&gt;&gt; }<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; switch B.b {<br>
&gt;&gt;&gt; case .b:<br>
&gt;&gt;&gt;&nbsp; &nbsp; print("b")<br>
&gt;&gt;&gt; default:<br>
&gt;&gt;&gt;&nbsp; &nbsp; print("somethine else")<br>
&gt;&gt;&gt; }<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; bar(b: B.bbb) // fine, because the switch statement on enums without<br>
&gt;&gt;&gt; // `@closed` has always`default`<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; // Allowed because `C` is open, and open allows sub-typing, conforming<br>
&gt;&gt;&gt; // and overriding to the client<br>
&gt;&gt;&gt; enum SubC : C {<br>
&gt;&gt;&gt;&nbsp; &nbsp; case cc<br>
&gt;&gt;&gt; }<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; let subC =<br>
&gt;&gt;&gt; <a href="http://SubC.cc">SubC.cc</a><br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; cool(c: subC) // okay<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; enum SubD : D {<br>
&gt;&gt;&gt;&nbsp; &nbsp; case dd<br>
&gt;&gt;&gt; }<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; doo(d: D.dd)// error, downgrade sub-enum to D first<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; My point here is, that we should not think of (possible) open enums as enums that the client is allowed to extend. That way we’re only creating another inconsistent case for the open access modifier. As far as I can tell, open as for today means “the client is allowed to subclass/override things from a different module”.<br>
&gt;&gt;&gt;<br>
&gt;&gt; Yes, but subclasses are analogous to enum cases.&nbsp; A subtype of an enum would remove cases.&nbsp; I think you are misunderstanding the relationship of enums to classes and protocols.<br>
&gt;&gt;<br>
&gt;&gt;&gt; And I already said it hundred of times that we should extend this to make open a true access modifier in Swift. That said the meaning of open should become:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;&nbsp; &nbsp; • The client is allowed to sub-type (currently only classes are supported).<br>
&gt;&gt;&gt;&nbsp; &nbsp; • The client is allowed to conform to open protocols<br>
&gt;&gt;&gt;&nbsp; &nbsp; • The client is allowed to override open type members<br>
&gt;&gt;&gt; This also means that extensibility is still allowed to public types. Public-but-not-open classes are still extensible today, which is the correct behavior. Extending an enum which is not closed could or probably should be made possible through extensions, because I cannot think of anther elegant way for the client to do so.<br>
&gt;&gt;&gt;<br>
&gt;&gt; This is what `open enum` would allow.&nbsp; It is the proper enum analogue of open classes.<br>
&gt;&gt;<br>
&gt;&gt;&gt; That will leave us the possibility to think of sub-typing enums in the future (I sketched it out a little above).<br>
&gt;&gt;&gt;<br>
&gt;&gt; Value subtyping is very interesting.&nbsp; I have been working on some ideas around this but I want to keep this thread focused.<br>
&gt;&gt;<br>
&gt;&gt;&gt; If I’m not mistaken, every enum case is known at compile time,<br>
&gt;&gt;&gt;<br>
&gt;&gt; This is true today but will not always be true in the future.&nbsp; That is in large part what this thread is about.<br>
&gt;&gt;<br>
&gt;&gt;&gt; which means to me that we can safely check the case before allowing to assign or pass an instance of a sub-enum to some of its super-enum. (Downgrading an enum case means that you will have to write some code that either mutates your current instance or creates a new one which matches one of the super-enum cases.) Furthermore that allows a clear distinction of what open access modifier does and how @closed behaves.<br>
&gt;&gt;&gt;<br>
&gt;&gt; I'm not going to comment on the rest because it is premised on a misunderstanding of what value subtyping is.&nbsp; I'm going to share some ideas around value subtyping in a new thread as soon as I have a chance to finish putting them together.<br>
&gt;&gt;<br>
&gt;&gt;&gt; To summarize:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;&nbsp; &nbsp; • @closed enum - you’re not allowed to add new cases to the enum in your lib + (you’re allowed to create sub-enums)<br>
&gt;&gt;&gt;&nbsp; &nbsp; • @closed public enum - you and the client are not allowed to add new cases (+ the client is not allowed to create sub-enums)<br>
&gt;&gt;&gt;&nbsp; &nbsp; • @closed open enum - you and the client are not allowed to add new cases (+ the client might create new sub-enums)<br>
&gt;&gt;&gt;&nbsp; &nbsp; • enum - you’re allowed to add new cases (default is needed in switch statements) (+ you can create new sub-enums)<br>
&gt;&gt;&gt;&nbsp; &nbsp; • public enum - you and the client are allowed to add new cases (+ only you are allowed to create new sub-enums)<br>
&gt;&gt;&gt;&nbsp; &nbsp; • open enum - you and the client are allowed to add new cases (everyone can create new sub-enums)<br>
&gt;&gt;&gt; This is a lot of bike shedding of mine, and the idea might not even see any light in Swift at all, but I’d like to share my ideas with the community. Feel free to criticize them or flesh something out into something real. :)<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; P.S.: If we had something like this:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; @closed enum X {<br>
&gt;&gt;&gt;&nbsp; &nbsp; case x, y<br>
&gt;&gt;&gt;&nbsp; &nbsp; func foo() {<br>
&gt;&gt;&gt;&nbsp; &nbsp; &nbsp;switch self {<br>
&gt;&gt;&gt;&nbsp; &nbsp; &nbsp; &nbsp; case .x, .y:<br>
&gt;&gt;&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print("swift")<br>
&gt;&gt;&gt;&nbsp; &nbsp; }<br>
&gt;&gt;&gt; }<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; enum Z : X {<br>
&gt;&gt;&gt;&nbsp; &nbsp; case z, zz<br>
&gt;&gt;&gt;&nbsp; &nbsp; override func foo() {<br>
&gt;&gt;&gt;&nbsp; &nbsp; &nbsp; &nbsp; // Iff `self` is `z` or `zz` then calling super will result in an error.<br>
&gt;&gt;&gt;&nbsp; &nbsp; &nbsp; &nbsp; // Possible solution: always tell the client to downgrade explicitly the<br>
&gt;&gt;&gt;&nbsp; &nbsp; &nbsp; &nbsp; // case first if there is an attempt to call super (if mutating),<br>
&gt;&gt;&gt;&nbsp; &nbsp; &nbsp; &nbsp; // or handle all cases<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;&nbsp; &nbsp; &nbsp; &nbsp; switch self {<br>
&gt;&gt;&gt;&nbsp; &nbsp; &nbsp; &nbsp; case .z, .zz:<br>
&gt;&gt;&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print("custom work")<br>
&gt;&gt;&gt;&nbsp; &nbsp; &nbsp; &nbsp; default: // or all super-enum cases<br>
&gt;&gt;&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; super.foo()<br>
&gt;&gt;&gt;&nbsp; &nbsp; &nbsp; &nbsp; }<br>
&gt;&gt;&gt;&nbsp; &nbsp; }<br>
&gt;&gt;&gt; }<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; --<br>
&gt;&gt;&gt; Adrian Zubarev<br>
&gt;&gt;&gt; Sent with Airmail<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Am 11. Februar 2017 um 04:49:11, Xiaodi Wu via swift-evolution (<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>) schrieb:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; On Wed, Feb 8, 2017 at 5:05 PM, Matthew Johnson via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br>
&gt;&gt;&gt;&gt; I’ve been thinking a lot about our public access modifier story lately in the context of both protocols and enums.&nbsp; I believe we should move further in the direction we took when introducing the `open` keyword.&nbsp; I have identified what I think is a promising direction and am interested in feedback from the community.&nbsp; If community feedback is positive I will flesh this out into a more complete proposal draft.<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; Background and Motivation:<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; In Swift 3 we had an extended debate regarding whether or not to allow inheritance of public classes by default or to require an annotation for classes that could be subclassed outside the module.&nbsp; The decision we reached was to avoid having a default at all, and instead make `open` an access modifier.&nbsp; The result is library authors are required to consider the behavior they wish for each class.&nbsp; Both behaviors are equally convenient (neither is penalized by requiring an additional boilerplate-y annotation).<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; A recent thread (<a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20170206/031566.html" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>pipermail/swift-evolution/<wbr>Week-of-Mon-20170206/031566.<wbr>html</a>) discussed a similar tradeoff regarding whether public enums should commit to a fixed set of cases by default or not.&nbsp; The current behavior is that they *do* commit to a fixed set of cases and there is no option (afaik) to modify that behavior.&nbsp; The Library Evolution document (<a href="https://github.com/apple/swift/blob/master/docs/LibraryEvolution.rst#enums" rel="noreferrer" target="_blank">https://github.com/apple/<wbr>swift/blob/master/docs/<wbr>LibraryEvolution.rst#enums</a>) suggests a desire to change this before locking down ABI such that public enums *do not* make this commitment by default, and are required to opt-in to this behavior using an `@closed` annotation.<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; In the previous discussion I stated a strong preference that closed enums *not* be penalized with an additional annotation.&nbsp; This is because I feel pretty strongly that it is a design smell to: 1) expose cases publicly if consumers of the API are not expected to switch on them and 2) require users to handle unknown future cases if they are likely to switch over the cases in correct use of the API.<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; The conclusion I came to in that thread is that we should adopt the same strategy as we did with classes: there should not be a default.<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; There have also been several discussions both on the list and via Twitter regarding whether or not we should allow closed protocols.&nbsp; In a recent Twitter discussion Joe Groff suggested that we don’t need them because we should use an enum when there is a fixed set of conforming types.&nbsp; There are at least two&nbsp; reasons why I still think we *should* add support for closed protocols.<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; As noted above (and in the previous thread in more detail), if the set of types (cases) isn’t intended to be fixed (i.e. the library may add new types in the future) an enum is likely not a good choice.&nbsp; Using a closed protocol discourages the user from switching and prevents the user from adding conformances that are not desired.<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; Another use case supported by closed protocols is a design where users are not allowed to conform directly to a protocol, but instead are required to conform to one of several protocols which refine the closed protocol.&nbsp; Enums are not a substitute for this use case.&nbsp; The only option is to resort to documentation and runtime checks.<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; Proposal:<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; This proposal introduces the new access modifier `closed` as well as clarifying the meaning of `public` and expanding the use of `open`.&nbsp; This provides consistent capabilities and semantics across enums, classes and protocols.<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; `open` is the most permissive modifier.&nbsp; The symbol is visible outside the module and both users and future versions of the library are allowed to add new cases, subclasses or conformances.&nbsp; (Note: this proposal does not introduce user-extensible `open` enums, but provides the syntax that would be used if they are added to the language)<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; `public` makes the symbol visible without allowing the user to add new cases, subclasses or conformances.&nbsp; The library reserves the right to add new cases, subclasses or conformances in a future version.<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; `closed` is the most restrictive modifier.&nbsp; The symbol is visible publicly with the commitment that future versions of the library are *also* prohibited from adding new cases, subclasses or conformances.&nbsp; Additionally, all cases, subclasses or conformances must be visible outside the module.<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; Note: the `closed` modifier only applies to *direct* subclasses or conformances.&nbsp; A subclass of a `closed` class need not be `closed`, in fact it may be `open` if the design of the library requires that.&nbsp; A class that conforms to a `closed` protocol also need not be `closed`.&nbsp; It may also be `open`.&nbsp; Finally, a protocol that refines a `closed` protocol need not be `closed`.&nbsp; It may also be `open`.<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; This proposal is consistent with the principle that libraries should opt-in to all public API contracts without taking a position on what that contract should be.&nbsp; It does this in a way that offers semantically consistent choices for API contract across classes, enums and protocols.&nbsp; The result is that the language allows us to choose the best tool for the job without restricting the designs we might consider because some kinds of types are limited with respect to the `open`, `public` and `closed` semantics a design might require.<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; Source compatibility:<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; This proposal affects both public enums and public protocols.&nbsp; The current behavior of enums is equivalent to a `closed` enum under this proposal and the current behavior of protocols is equivalent to an `open` protocol under this proposal.&nbsp; Both changes allow for a simple mechanical migration, but that may not be sufficient given the source compatibility promise made for Swift 4.&nbsp; We may need to identify a multi-release strategy for adopting this proposal.<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; Brent Royal-Gordon suggested such a strategy in a discussion regarding closed protocols on Twitter:<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; * In Swift 4: all unannotated public protocols receive a warning, possibly with a fix-it to change the annotation to `open`.<br>
&gt;&gt;&gt;&gt; * Also in Swift 4: an annotation is introduced to opt-in to the new `public` behavior.&nbsp; Brent suggested `@closed`, but as this proposal distinguishes `public` and `closed` we would need to identify something else.&nbsp; I will use `@annotation` as a placeholder.<br>
&gt;&gt;&gt;&gt; * Also In Swift 4: the `closed` modifier is introduced.<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; * In Swift 5 the warning becomes a compiler error.&nbsp; `public protocol` is not allowed.&nbsp; Users must use `@annotation public protocol`.<br>
&gt;&gt;&gt;&gt; * In Swift 6 `public protocol` is allowed again, now with the new semantics.&nbsp; `@annotation public protocol` is also allowed, now with a warning and a fix-it to remove the warning.<br>
&gt;&gt;&gt;&gt; * In Swift 7 `@annotation public protocol` is no longer allowed.<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; A similar mult-release strategy would work for migrating public enums.<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; A different line of feedback here:<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; As per previous reply, I now think if we clarify the mental model of the access modifier hierarchy you're proposing and adopt or reject with that clarity, we'll be fine whether we go with `closed` or with `@closed`. But I don't think the source compatibility strategy you list is the most simple or the most easy to understand for end users.<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; - I'll leave aside closed protocols, which as per Jordan Rose's feedback may or may not have sufficient interestingness.<br>
&gt;&gt;&gt;&gt; - With respect to enums, I don't think we need such a drastic whiplash in terms of what will compile in future versions. Instead, we could take a more pragmatic approach:<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; 1. In Swift 4, remove the warning (or is it error?) about `default` cases in switch statements over public enums. Simultaneously, add `closed` or `@closed` (whatever is the approved spelling) and start annotating standard library APIs. The annotation will be purely future-proofing and have no functional effect (i.e. the compiler will do nothing differently for a `closed enum` or `@closed public enum` (as the case may be) versus a plain `public enum`).<br>
&gt;&gt;&gt;&gt; 2. In Swift 4.1, _warn_ if switch statements over public enums don't have a `default` statement: offer a fix-it to insert `default: fatalError()` and, if the enum is in the same project, offer a fix-it to insert `closed` or `@closed`.<br>
&gt;&gt;&gt;&gt; 3. In Swift 5, upgrade the warning to an error for non-exhaustiveness if a switch statement over a public enum doesn't have a `default` statement. Now, new syntax to extend an `open enum` can be introduced and the compiler can treat closed and public enums differently.<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; ______________________________<wbr>_________________<br>
&gt;&gt;&gt;&gt; swift-evolution mailing list<br>
&gt;&gt;&gt;&gt; <a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
&gt;&gt;&gt;&gt; <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; ______________________________<wbr>_________________<br>
&gt;&gt;&gt; swift-evolution mailing list<br>
&gt;&gt;&gt; <a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
&gt;&gt;&gt; <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br>
&gt;&gt; ______________________________<wbr>_________________<br>
&gt;&gt; swift-evolution mailing list<br>
&gt;&gt; <a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
&gt;&gt; <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br>
&gt;<br>
<br>
______________________________<wbr>_________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br>
</div></div></blockquote></div><br></div></div>
</div></blockquote></div></body></html>