Uploaded image for project: 'Swift'
  1. Swift
  2. SR-10077

Switching over duplicate enum case names won't compile

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Medium
    • Resolution: Unresolved
    • Component/s: Compiler
    • Labels:
      None

      Description

      In Swift 4.2 (Xcode 10.1) and 5.0 (Xcode 10.2 beta 4), it's legal to define multiple identical enum cases as long as their associated value is different:

      enum PictureImport {
          case add(image: UIImage)
          case add(data: Data)
      }
      

       This, however, leads to compile errors when switching:

      func importImage(_ importedImage: PictureImport) {
          switch importedImage {
          case .add(image: let image): // Error: Tuple pattern element label 'image' must be 'data'
              // ...
          case .add(data: let data):
              // ...
          }
      }
      

      (Maybe related to https://bugs.swift.org/browse/SR-6853)

        Attachments

          Activity

            People

            • Assignee:
              slavapestov Slava Pestov
              Reporter:
              xavier.lowmiller Xavier Lowmiller
            • Votes:
              2 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

              • Created:
                Updated: