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

Enum cases named "none" can cause ambiguity with Optional's "none"

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Duplicate
    • Component/s: None
    • Labels:
      None

      Description

      In the following code snippet, foo is actually nil because the compiler decides to pick Optional.none instead of MyTest.none. I spent a long time tracking this down!  

      enum MyTest: UInt8 {
         case none, one, two, three
      }
      let foo: MyTest? = .none
      

      Another case where this occurs is in code like this:

      if foo == .none { \* stuff *\ }
      

      There are no warnings when this happens. I think there should probably at least be a fixit warning that says something about there being an ambiguity here and offering the user fix it with either `Optional.none` or `MyTest.none`.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                bigzaphod Sean Heber
                Reporter:
                bigzaphod Sean Heber
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: