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

Odd Name Lookup in Switch Statements

    XMLWordPrintable

    Details

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

      Xcode Version 9.3.1 (9E501)

      Description

      Name lookup in switch statements seems buggy. I'll demonstrate the issue with a few examples, showing issues ranging from bad diagnostics to what I consider to be bugs:

       

      enum A { case one }
      enum B { case one }
      
      let e = A.one
      
      switch e {
        case A.one: print("one")
        case B.one: print("one") // error: Enum case 'one' is not a member of type 'A'
      }
      

       

      enum A { case one }
      
      let e: A? = A.one
      
      switch e {
        case A.one: print("one") // error: Enum case 'one' is not a member of type 'A?'
      }
      

       

      struct S {
        var i: Int
        static var ten: S { return S(i: 10)}
      }
      
      let s: S? = .ten
      
      switch s {
        case .ten: print("ten") // error: enum case 'ten' not found in type 'S?'
        default: print("default")
      }
      

      You can see more examples and some discussion in this forum thread.

       

       

       

        Attachments

          Activity

            People

            Assignee:
            Unassigned
            Reporter:
            jawbroken jawbroken
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated: