[Returned for Revision] SE-0295: Codable Synthesis for enums with Associated Values

After discussing the proposal, the core team has decided to return SE-0295 for revision.

We agree that having a default Coding synthesis for enum s with payloads is valuable. Although the encoding may not be perfect for every use case, the default encoding is still valuable as it simplifies the cases where the encoding is sufficient. For the other use cases, the user is still able define the synthesis as they could previously.

Furthermore, the extensibility of Codable is beyond the scope of this proposal as is the "readability" of the serialization itself. The design choices of Codable are not grounds for preventing improvements to serialization in Swift.

The review additionally brought up points of repeated keys e.g.:

enum E {
  case c(key: Int, key: Int)
}

This functionality is not intentional, and the compiler no longer accepts this construct and as a result, the proposal does not need to support this.

The core team would like to see the proposal consider additional enum types, including overloaded cases. The proposal is returned for revisions, with the intended focus being purely the extension of cases that can be handled for the default synthesis.

Thank you to everyone who participated in the review and helped improve the proposal.

Saleem Abdulrasool
Review Manager

12 Likes

Pattern matching of "overloaded cases" seems to be broken.

Details
enum Test {
  case base(arg1: Int)
  case base(arg2: String)
}

let test: Test = Bool.random() ? .base(arg1: 1) : .base(arg2: "2")

switch test {
case .base(arg1: let value):
  print(value)
case .base(arg2: let value):
  print(value)
}
  • Swift 5.3.2 fails with an error:

    case .base(arg1: let value):
      //       ^
      // error: Tuple pattern element label 'arg1' must be 'arg2'
    
  • The latest main-branch snapshot fails with an assertion:

    Assertion failed: (!foundElement && "ambiguity in enum case name lookup?!"), function filterForEnumElement, file /Users/buildnode/jenkins/workspace/oss-swift-package-macos/swift/lib/Sema/TypeCheckPattern.cpp, line 99.

  • The partial implementation and expiration of SE-0155 has confused me.

  • The Swift Programming Language book still refers to an associated tuple value.

1 Like
Terms of Service

Privacy Policy

Cookie Policy