What is the status of SE-0155? And other questions

I was going to ask about if we should add expressions like:

EXPRESSION “cases” IDENTIFIER

as a way to test enum-cases inline. Then I found out about SE-0155 “Normalize Enum Case Representation,” which allows cases to share a base name. Has this been implemented for Swift 5 (and the SE-0155 page not yet updated)? Or is it still being worked on?

My other query is: how can base-name-sharing enum cases differ? I know you can’t have a zero-parameter payload; the case must either be payload-less or use a single dummy Void parameter (or both). For cases with parameters, do they have to be all labeled or all labelless? Or are partially-labelled payloads allowed?

Right now I’m imagining:

xxx cases myCase  // all cases named “myCase”
xxx cases myCase(:::)  // all cases named “myCase” with 3 parameters
xxx cases myCase(_: _: _:)  // all cases named “myCase” with 3 label-less parameters
xxx cases myCase(first: :)  // all cases named “myCase” with 2 parameters, first named “first”, second with any label (including none)

Are cases with the same name, parameter count, and labels allowed that differ only by parameter type? I hope not, as that would require use to add the types to the above expressions for differentiation.

Oh, I just realized that the above interpretation allows no way to check if a case matches exactly with a payload-less variant. (It always matches all variants without regard to the payload) I guess we need to make all signatures exact matches.

The question remains: What's up with SE-0155? @codafi has done incredible work on it and it was merged into master a month ago (https://github.com/apple/swift/pull/21381#)

There is incredibly good stuff in this Proposal. Can we expect to get it in Swift 5.1? Pretty please?

Anything merged into master before March 18th is automatically in the Swift 5.1 branch. So, unless somebody makes a deliberate action to remove it, it’ll probably stay in.

1 Like

Default arguments for enum cases have been implemented, however one part of SE-0155 still missing is full support for compound names. Right now you cannot define two cases with the same base name.

There was also a mistake in the mangling for resilient enum cases; only the base name is mangled and not the labels. Fixing this requires some kind of versioning, and at least resilient libraries using this feature will not backwards deploy to old compilers.

What does that mean in practice. So we don't get overloading cases with different arguments in Swift 5, and have to do a #if swift(>5.0) for the entire enum if we want to use that? User-libraries won't be resilient anyway (I guess) so it will work for us even without the check?