Warning when omitting default case for imported enums

You'd still get the compiler helping you with new cases when working with enums within your module.

That's my point. My projects usually consist of several modules, as I've noted and I don't need to extend the enum from the other module (and in 99% of the cases it wouldn't make sense).

And you'd get no error in the other modules, which is terrible if your default label goes to fatalError and you need to catch all these cases at runtime.

Example:

My project consists of Core framework that is shared among all my projects, then the app has AppCore that uses the Core framework and is shared between macOS and iOS apps and then I have the actual app.

I.e. 3 modules that make one app. No need to extend enums. None so far. With what you suggest, I define an enum in the Core framework, AppCore and the App modules need to add "default" clause to their switch statements, usually fatalError, since that's the only plausible thing to do.

Adding another member to the enum (in Core) does not create errors/warnings in AppCore and App, so the new enum case is handled by fatalError, causing the app to crash at runtime.

There's less use in having the compiler help you find new cases when they can only be added between major versions of a package. The benefit to cost ratio here is imbalanced. Enum cases are forever frozen from version x.0.0 of a package forward (until the next major bump). No other programming language I know of prevents adding enum cases in a minor release. This makes using enums in public API (which are incredibly useful) very difficult to do while following semver.

Not really. I have many in-house frameworks that can simply add enum values - since it's all within my projects, I don't need to worry about breaking 3rd party code.

Could you explain more what you mean by public vs open enums?

Now you have two ways to offer class API to another module:

- declare it public - to the other module, it appears as "final".
- declare it open - in the other module, it can be subclassed and members declared as open can be overridden

In the same sense, you would declare an enum "open" instead of "public" to allow new members to be declared.

···

On Feb 7, 2017, at 7:54 PM, Tanner Nelson <tanner@qutheory.io> wrote:

Best,
Tanner

Sent from my iPhone

On Feb 7, 2017, at 16:21, Charlie Monroe <charlie@charliemonroe.net <mailto:charlie@charliemonroe.net>> wrote:

-1

Not having the default case allows you to rely on the compiler to handle new options once they are added. Most of my apps consist nowadays from multiple modules and this would be massively inconvenient.

The possible future features may be non-breaking if we consider that we will not allow enums to be extended by default, but would need to be marked explicitely as extendable. Similar to public vs. open classes.

On Feb 7, 2017, at 4:12 PM, Tanner Nelson via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

Hello Swift Evolution,

I'd like to propose that a warning be emitted when default cases are omitted for enums from other modules.

What this would look like:

OtherModule:

public enum SomeEnum {
    case one
    case two
}

public let global: SomeEnum = .one

executable:

import OtherModule

switch OtherModule.global {
    case .one: break
    case .two: break
    ^~~~~ ⚠︎ Warning: Default case recommended for imported enums. Fix-it: Add `default: break`
}

Why:

Allowing the omission of a default case in an exhaustive switch makes the addition of a new case to the enum a breaking change.
In other words, if you're exhaustively switching on an enum from an imported library, the imported library can break your code by adding a new case to that enum (which the library authors may erroneously view as an additive/minor-bump change).

Background:

As a maintainer of a Swift framework, public enums have been a pain point in maintaining semver. They've made it difficult to implement additive features and have necessitated the avoidance of enums in our future public API plans.

Related Twitter thread: https://twitter.com/tanner0101/status/796860273760104454

Looking forward to hearing your thoughts.

Best,
Tanner

Tanner Nelson
Vapor
+1 (435) 773-2831

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution

I'm not sure if I like the concept of having two kinds of enum.

Why not? Bool-like enums would be declared ‘closed’, and would not require a default case (but adding a new case would then break ABI).

Well, enums are already (relative) complex, and with this addition, there would be six different flavors.
Imho it would be less bad if we could recycle existing modifiers, but with a hypothetic "closed" access level added as well, I have strong doubts that the feature carries its weight.

For better or worse we need the ability to define enums that admit new cases without breaking ABI. Whether or not this is the default for all enums, or enabled with a special attribute can be designed later when we send out evolution proposals for resilience-related features.

Intuitively, I thought this should not affect ABI… but no matter what instability this is, I guess it could definitely crash an application that is confronted with an unexpected case ;-)

Wouldn't it be possible to create an implicit default case for every switch-statement?

-1 This warning suggestion is of highly questionable value. Authors are free to add a default case or not, depending upon the nature of the enum and the logic to handle them. There is no “right” way to suggest, although for high-reliability code, default cases should usually be avoided in my opinion.

···

On Feb 7, 2017, at 11:49 AM, Rien via swift-evolution <swift-evolution@swift.org> wrote:

If you don’t want the default case, and if you like a warning free compilation, you need a way to suppress the warning.

Regards,
Rien

Site: http://balancingrock.nl
Blog: http://swiftrien.blogspot.com
Github: Balancingrock (Rien) · GitHub
Project: http://swiftfire.nl

On 07 Feb 2017, at 19:42, Tanner Nelson <tanner@qutheory.io> wrote:

I don't understand the part about warning suppression. The warning would go away when you add the default case.

Sent from my iPhone

On Feb 7, 2017, at 16:25, Rien <Rien@Balancingrock.nl> wrote:

-1

Reason 1: the “negative” behaviour you describe is actually exactly what I want to happen.
Reason 2: Introducing a warning would also necessitate a warning suppression in order to have your code compile without warnings. But when you suppress, the purpose of the warning is nul and void.

PS: I would suggest not to use an enum in cases where this is really annoying and replace the enums with constants.

Regards,
Rien

Site: http://balancingrock.nl
Blog: http://swiftrien.blogspot.com
Github: Balancingrock (Rien) · GitHub
Project: http://swiftfire.nl

On 07 Feb 2017, at 16:12, Tanner Nelson via swift-evolution <swift-evolution@swift.org> wrote:

Hello Swift Evolution,

I'd like to propose that a warning be emitted when default cases are omitted for enums from other modules.

What this would look like:

OtherModule:

public enum SomeEnum {
 case one
 case two
}

public let global: SomeEnum = .one

executable:

import OtherModule

switch OtherModule.global {
 case .one: break
 case .two: break
 ^~~~~ ⚠︎ Warning: Default case recommended for imported enums. Fix-it: Add `default: break`
}

Why:

Allowing the omission of a default case in an exhaustive switch makes the addition of a new case to the enum a breaking change.
In other words, if you're exhaustively switching on an enum from an imported library, the imported library can break your code by adding a new case to that enum (which the library authors may erroneously view as an additive/minor-bump change).

Background:

As a maintainer of a Swift framework, public enums have been a pain point in maintaining semver. They've made it difficult to implement additive features and have necessitated the avoidance of enums in our future public API plans.

Related Twitter thread: https://twitter.com/tanner0101/status/796860273760104454

Looking forward to hearing your thoughts.

Best,
Tanner

Tanner Nelson
Vapor
+1 (435) 773-2831

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

The point of the warning is to inform you that the author of the library you depend on could cause your could not to compile by simply adding a case to that enum.

This is something you should be happy to avoid as someone writing a library you want other people to depend on or as someone writing an application that you don't want to find failing to compile in a few weeks or months.

···

Sent from my iPhone

On Feb 7, 2017, at 19:49, Rien <Rien@Balancingrock.nl> wrote:

If you don’t want the default case, and if you like a warning free compilation, you need a way to suppress the warning.

Regards,
Rien

Site: http://balancingrock.nl
Blog: http://swiftrien.blogspot.com
Github: Balancingrock (Rien) · GitHub
Project: http://swiftfire.nl

On 07 Feb 2017, at 19:42, Tanner Nelson <tanner@qutheory.io> wrote:

I don't understand the part about warning suppression. The warning would go away when you add the default case.

Sent from my iPhone

On Feb 7, 2017, at 16:25, Rien <Rien@Balancingrock.nl> wrote:

-1

Reason 1: the “negative” behaviour you describe is actually exactly what I want to happen.
Reason 2: Introducing a warning would also necessitate a warning suppression in order to have your code compile without warnings. But when you suppress, the purpose of the warning is nul and void.

PS: I would suggest not to use an enum in cases where this is really annoying and replace the enums with constants.

Regards,
Rien

Site: http://balancingrock.nl
Blog: http://swiftrien.blogspot.com
Github: Balancingrock (Rien) · GitHub
Project: http://swiftfire.nl

On 07 Feb 2017, at 16:12, Tanner Nelson via swift-evolution <swift-evolution@swift.org> wrote:

Hello Swift Evolution,

I'd like to propose that a warning be emitted when default cases are omitted for enums from other modules.

What this would look like:

OtherModule:

public enum SomeEnum {
 case one
 case two
}

public let global: SomeEnum = .one

executable:

import OtherModule

switch OtherModule.global {
 case .one: break
 case .two: break
 ^~~~~ ⚠︎ Warning: Default case recommended for imported enums. Fix-it: Add `default: break`
}

Why:

Allowing the omission of a default case in an exhaustive switch makes the addition of a new case to the enum a breaking change.
In other words, if you're exhaustively switching on an enum from an imported library, the imported library can break your code by adding a new case to that enum (which the library authors may erroneously view as an additive/minor-bump change).

Background:

As a maintainer of a Swift framework, public enums have been a pain point in maintaining semver. They've made it difficult to implement additive features and have necessitated the avoidance of enums in our future public API plans.

Related Twitter thread: https://twitter.com/tanner0101/status/796860273760104454

Looking forward to hearing your thoughts.

Best,
Tanner

Tanner Nelson
Vapor
+1 (435) 773-2831

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Adding a default case when you've exhaustively switched on the enum results in a warning currently. The default case is not really optional at that point if you want to compile without warnings.

warning: default will never be executed default: break
···

Sent from my iPhone

On Feb 7, 2017, at 20:13, Christopher Kornher <ckornher@me.com> wrote:

-1 This warning suggestion is of highly questionable value. Authors are free to add a default case or not, depending upon the nature of the enum and the logic to handle them. There is no “right” way to suggest, although for high-reliability code, default cases should usually be avoided in my opinion.

On Feb 7, 2017, at 11:49 AM, Rien via swift-evolution <swift-evolution@swift.org> wrote:

If you don’t want the default case, and if you like a warning free compilation, you need a way to suppress the warning.

Regards,
Rien

Site: http://balancingrock.nl
Blog: http://swiftrien.blogspot.com
Github: Balancingrock (Rien) · GitHub
Project: http://swiftfire.nl

On 07 Feb 2017, at 19:42, Tanner Nelson <tanner@qutheory.io> wrote:

I don't understand the part about warning suppression. The warning would go away when you add the default case.

Sent from my iPhone

On Feb 7, 2017, at 16:25, Rien <Rien@Balancingrock.nl> wrote:

-1

Reason 1: the “negative” behaviour you describe is actually exactly what I want to happen.
Reason 2: Introducing a warning would also necessitate a warning suppression in order to have your code compile without warnings. But when you suppress, the purpose of the warning is nul and void.

PS: I would suggest not to use an enum in cases where this is really annoying and replace the enums with constants.

Regards,
Rien

Site: http://balancingrock.nl
Blog: http://swiftrien.blogspot.com
Github: Balancingrock (Rien) · GitHub
Project: http://swiftfire.nl

On 07 Feb 2017, at 16:12, Tanner Nelson via swift-evolution <swift-evolution@swift.org> wrote:

Hello Swift Evolution,

I'd like to propose that a warning be emitted when default cases are omitted for enums from other modules.

What this would look like:

OtherModule:

public enum SomeEnum {
case one
case two
}

public let global: SomeEnum = .one

executable:

import OtherModule

switch OtherModule.global {
case .one: break
case .two: break
^~~~~ ⚠︎ Warning: Default case recommended for imported enums. Fix-it: Add `default: break`
}

Why:

Allowing the omission of a default case in an exhaustive switch makes the addition of a new case to the enum a breaking change.
In other words, if you're exhaustively switching on an enum from an imported library, the imported library can break your code by adding a new case to that enum (which the library authors may erroneously view as an additive/minor-bump change).

Background:

As a maintainer of a Swift framework, public enums have been a pain point in maintaining semver. They've made it difficult to implement additive features and have necessitated the avoidance of enums in our future public API plans.

Related Twitter thread: https://twitter.com/tanner0101/status/796860273760104454

Looking forward to hearing your thoughts.

Best,
Tanner

Tanner Nelson
Vapor
+1 (435) 773-2831

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

I'm not sure if I like the concept of having two kinds of enum.

Why not? Bool-like enums would be declared ‘closed’, and would not require a default case (but adding a new case would then break ABI).

Well, enums are already (relative) complex, and with this addition, there would be six different flavors.
Imho it would be less bad if we could recycle existing modifiers, but with a hypothetic "closed" access level added as well, I have strong doubts that the feature carries its weight.

For better or worse we need the ability to define enums that admit new cases without breaking ABI. Whether or not this is the default for all enums, or enabled with a special attribute can be designed later when we send out evolution proposals for resilience-related features.

Intuitively, I thought this should not affect ABI… but no matter what instability this is, I guess it could definitely crash an application that is confronted with an unexpected case ;-)

Wouldn't it be possible to create an implicit default case for every switch-statement?

What do you suggest this implicit default case do? Just break? That seems like the only option besides trapping. I wouldn’t want the compiler doing either of these after the fact. If we’re going to allow a library to add new cases without making that a breaking change it must communicate that to users *ahead of time* and the compiler must require a default clause in any switch over that type.

···

On Feb 10, 2017, at 10:55 AM, Tino Heth via swift-evolution <swift-evolution@swift.org> wrote:

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

I'm not sure if I like the concept of having two kinds of enum.

Why not? Bool-like enums would be declared ‘closed’, and would not require a default case (but adding a new case would then break ABI).

Well, enums are already (relative) complex, and with this addition, there would be six different flavors.
Imho it would be less bad if we could recycle existing modifiers, but with a hypothetic "closed" access level added as well, I have strong doubts that the feature carries its weight.

Closed would not be an access level, just an attribute orthogonal to the others. What do you mean by the six different flavors?

···

On Feb 10, 2017, at 8:55 AM, Tino Heth <2th@gmx.de> wrote:

For better or worse we need the ability to define enums that admit new cases without breaking ABI. Whether or not this is the default for all enums, or enabled with a special attribute can be designed later when we send out evolution proposals for resilience-related features.

Intuitively, I thought this should not affect ABI… but no matter what instability this is, I guess it could definitely crash an application that is confronted with an unexpected case ;-)

Wouldn't it be possible to create an implicit default case for every switch-statement?

I'm not sure if I like the concept of having two kinds of enum.

Why not? Bool-like enums would be declared ‘closed’, and would not require
a default case (but adding a new case would then break ABI).

Well, enums are already (relative) complex, and with this addition, there
would be six different flavors.
Imho it would be less bad if we could recycle existing modifiers, but with
a hypothetic "closed" access level added as well, I have strong doubts that
the feature carries its weight.

Closed would not be an access level, just an attribute orthogonal to the
others. What do you mean by the six different flavors?

My read of Matthew Johnson's pitch is that `closed` is to be a sixth access
level.

For better or worse we need the ability to define enums that admit new

···

On Fri, Feb 10, 2017 at 7:23 PM, Slava Pestov via swift-evolution < swift-evolution@swift.org> wrote:

On Feb 10, 2017, at 8:55 AM, Tino Heth <2th@gmx.de> wrote:
cases without breaking ABI. Whether or not this is the default for all
enums, or enabled with a special attribute can be designed later when we
send out evolution proposals for resilience-related features.

Intuitively, I thought this should not affect ABI… but no matter what
instability this is, I guess it could definitely crash an application that
is confronted with an unexpected case ;-)

Wouldn't it be possible to create an implicit default case for every
switch-statement?

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Closed would not be an access level, just an attribute orthogonal to the others.

As Xiaodi pointed out, there's still no agreement on that — so basically I'm saying that I prefer your interpretation, because imho five access levels are already a alarmingly high number.

What do you mean by the six different flavors?

1) cases with associated objects
2) raw-based enums
3) everything else (not that much different from int-based)

With the new attribute, there would be a new variant for each type, therefor six flavours (I choose this term because it's only small variation — but still, it might look quite complex to someone coming from C or Java).

The major issue I have with this change is how it will work in real live:
When I write a library and declare that I'll never add new cases to an enum, who will enforce this?
Will the compiler interact with git and look for release tags, or will there be a lockdown-command that records all cases and compares them with the last time the command was triggered?
This feels really brittle to me, and I haven't seen a approach that would be fundamental different (and better).

I can assure you that I most definitely do not want an API developer adding to an exposed enum without me -the user- noticing it.

That would imo be a recipe for disaster.

Regards,
Rien.

···

On 7 Feb 2017, at 19:58, Tanner Nelson <tanner@qutheory.io> wrote:

The point of the warning is to inform you that the author of the library you depend on could cause your could not to compile by simply adding a case to that enum.

This is something you should be happy to avoid as someone writing a library you want other people to depend on or as someone writing an application that you don't want to find failing to compile in a few weeks or months.

Sent from my iPhone

On Feb 7, 2017, at 19:49, Rien <Rien@Balancingrock.nl> wrote:

If you don’t want the default case, and if you like a warning free compilation, you need a way to suppress the warning.

Regards,
Rien

Site: http://balancingrock.nl
Blog: http://swiftrien.blogspot.com
Github: Balancingrock (Rien) · GitHub
Project: http://swiftfire.nl

On 07 Feb 2017, at 19:42, Tanner Nelson <tanner@qutheory.io> wrote:

I don't understand the part about warning suppression. The warning would go away when you add the default case.

Sent from my iPhone

On Feb 7, 2017, at 16:25, Rien <Rien@Balancingrock.nl> wrote:

-1

Reason 1: the “negative” behaviour you describe is actually exactly what I want to happen.
Reason 2: Introducing a warning would also necessitate a warning suppression in order to have your code compile without warnings. But when you suppress, the purpose of the warning is nul and void.

PS: I would suggest not to use an enum in cases where this is really annoying and replace the enums with constants.

Regards,
Rien

Site: http://balancingrock.nl
Blog: http://swiftrien.blogspot.com
Github: Balancingrock (Rien) · GitHub
Project: http://swiftfire.nl

On 07 Feb 2017, at 16:12, Tanner Nelson via swift-evolution <swift-evolution@swift.org> wrote:

Hello Swift Evolution,

I'd like to propose that a warning be emitted when default cases are omitted for enums from other modules.

What this would look like:

OtherModule:

public enum SomeEnum {
case one
case two
}

public let global: SomeEnum = .one

executable:

import OtherModule

switch OtherModule.global {
case .one: break
case .two: break
^~~~~ ⚠︎ Warning: Default case recommended for imported enums. Fix-it: Add `default: break`
}

Why:

Allowing the omission of a default case in an exhaustive switch makes the addition of a new case to the enum a breaking change.
In other words, if you're exhaustively switching on an enum from an imported library, the imported library can break your code by adding a new case to that enum (which the library authors may erroneously view as an additive/minor-bump change).

Background:

As a maintainer of a Swift framework, public enums have been a pain point in maintaining semver. They've made it difficult to implement additive features and have necessitated the avoidance of enums in our future public API plans.

Related Twitter thread: https://twitter.com/tanner0101/status/796860273760104454

Looking forward to hearing your thoughts.

Best,
Tanner

Tanner Nelson
Vapor
+1 (435) 773-2831

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

I have no objection against removing that warning.
The warning seems unnecessary to me.

Regards,
Rien

Site: http://balancingrock.nl
Blog: http://swiftrien.blogspot.com
Github: Balancingrock (Rien) · GitHub
Project: http://swiftfire.nl

···

On 07 Feb 2017, at 22:13, Tanner Nelson <tanner@qutheory.io> wrote:

Adding a default case when you've exhaustively switched on the enum results in a warning currently. The default case is not really optional at that point if you want to compile without warnings.

warning: default will never be executed default: break

Sent from my iPhone

On Feb 7, 2017, at 20:13, Christopher Kornher <ckornher@me.com> wrote:

-1 This warning suggestion is of highly questionable value. Authors are free to add a default case or not, depending upon the nature of the enum and the logic to handle them. There is no “right” way to suggest, although for high-reliability code, default cases should usually be avoided in my opinion.

On Feb 7, 2017, at 11:49 AM, Rien via swift-evolution <swift-evolution@swift.org> wrote:

If you don’t want the default case, and if you like a warning free compilation, you need a way to suppress the warning.

Regards,
Rien

Site: http://balancingrock.nl
Blog: http://swiftrien.blogspot.com
Github: Balancingrock (Rien) · GitHub
Project: http://swiftfire.nl

On 07 Feb 2017, at 19:42, Tanner Nelson <tanner@qutheory.io> wrote:

I don't understand the part about warning suppression. The warning would go away when you add the default case.

Sent from my iPhone

On Feb 7, 2017, at 16:25, Rien <Rien@Balancingrock.nl> wrote:

-1

Reason 1: the “negative” behaviour you describe is actually exactly what I want to happen.
Reason 2: Introducing a warning would also necessitate a warning suppression in order to have your code compile without warnings. But when you suppress, the purpose of the warning is nul and void.

PS: I would suggest not to use an enum in cases where this is really annoying and replace the enums with constants.

Regards,
Rien

Site: http://balancingrock.nl
Blog: http://swiftrien.blogspot.com
Github: Balancingrock (Rien) · GitHub
Project: http://swiftfire.nl

On 07 Feb 2017, at 16:12, Tanner Nelson via swift-evolution <swift-evolution@swift.org> wrote:

Hello Swift Evolution,

I'd like to propose that a warning be emitted when default cases are omitted for enums from other modules.

What this would look like:

OtherModule:

public enum SomeEnum {
case one
case two
}

public let global: SomeEnum = .one

executable:

import OtherModule

switch OtherModule.global {
case .one: break
case .two: break
^~~~~ ⚠︎ Warning: Default case recommended for imported enums. Fix-it: Add `default: break`
}

Why:

Allowing the omission of a default case in an exhaustive switch makes the addition of a new case to the enum a breaking change.
In other words, if you're exhaustively switching on an enum from an imported library, the imported library can break your code by adding a new case to that enum (which the library authors may erroneously view as an additive/minor-bump change).

Background:

As a maintainer of a Swift framework, public enums have been a pain point in maintaining semver. They've made it difficult to implement additive features and have necessitated the avoidance of enums in our future public API plans.

Related Twitter thread: https://twitter.com/tanner0101/status/796860273760104454

Looking forward to hearing your thoughts.

Best,
Tanner

Tanner Nelson
Vapor
+1 (435) 773-2831

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

I'm not sure if I like the concept of having two kinds of enum.

Why not? Bool-like enums would be declared ‘closed’, and would not require a default case (but adding a new case would then break ABI).

Well, enums are already (relative) complex, and with this addition, there would be six different flavors.
Imho it would be less bad if we could recycle existing modifiers, but with a hypothetic "closed" access level added as well, I have strong doubts that the feature carries its weight.

Closed would not be an access level, just an attribute orthogonal to the others. What do you mean by the six different flavors?

My read of Matthew Johnson's pitch is that `closed` is to be a sixth access level.

This is correct. It isn't immediately obvious, but when you step back and consider things from a high level point of view it seems to fall pretty naturally out of the logic we used when we made `open` and access level.

Closed is talking about the same thing `open` is: who is allowed to add to the set of cases, subclasses or protocols of an enum, class, or protocol. It just moves in the opposite direction from `public` than `open` does. Once you realize this, any other spelling of `closed` would make the language feel inconsistent IMO. If `open` works as an access level `closed` should also.

···

Sent from my iPad

On Feb 10, 2017, at 9:22 PM, Xiaodi Wu via swift-evolution <swift-evolution@swift.org> wrote:

On Fri, Feb 10, 2017 at 7:23 PM, Slava Pestov via swift-evolution <swift-evolution@swift.org> wrote:

On Feb 10, 2017, at 8:55 AM, Tino Heth <2th@gmx.de> wrote:

For better or worse we need the ability to define enums that admit new cases without breaking ABI. Whether or not this is the default for all enums, or enabled with a special attribute can be designed later when we send out evolution proposals for resilience-related features.

Intuitively, I thought this should not affect ABI… but no matter what instability this is, I guess it could definitely crash an application that is confronted with an unexpected case ;-)

Wouldn't it be possible to create an implicit default case for every switch-statement?

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Closed would not be an access level, just an attribute orthogonal to the others.

As Xiaodi pointed out, there's still no agreement on that — so basically I'm saying that I prefer your interpretation, because imho five access levels are already a alarmingly high number.

Well we're going to have a concept of closed enum regardless of how we spell it syntactically. I don't think making it an access level adds any complexity over using an attribute. I think it reduces complexity by making the language more consistent.

What do you mean by the six different flavors?

1) cases with associated objects
2) raw-based enums
3) everything else (not that much different from int-based)

With the new attribute, there would be a new variant for each type, therefor six flavours (I choose this term because it's only small variation — but still, it might look quite complex to someone coming from C or Java).

The major issue I have with this change is how it will work in real live:
When I write a library and declare that I'll never add new cases to an enum, who will enforce this?
Will the compiler interact with git and look for release tags, or will there be a lockdown-command that records all cases and compares them with the last time the command was triggered?
This feels really brittle to me, and I haven't seen a approach that would be fundamental different (and better).

We are not talking about *adding* closed enums to the language. They already exist and will continue to exist. We're just talking about how to spell them in the future when we also have resilient enums (i.e. allowing a library to add new cases in a future version without breaking compatibility). I don't have a complete answer here about the details, but there is a plan to provide tool support to help with library evolution and detecting breaking changes.

···

Sent from my iPad

On Feb 11, 2017, at 5:11 AM, Tino Heth via swift-evolution <swift-evolution@swift.org> wrote:

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution