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

Forced to cast twice for case pattern matching

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Done
    • Component/s: Compiler
    • Labels:
      None
    • Environment:

      macOS 10.12.6

      Xcode 8 and 9

      iOS cocoa frameworks

      Description

      I couldn't figure out a pure-Swift use case, but Apple's Cocoa framework seems to expose an issue with the compiler in regards to how values are cast within a case comparison.

       

      In these example case comparisons, kUTTypeImage is of type CFString.

       

       

      if case kUTTypeImage as String = "" { }
      

      I'd expect this line to work, but the compiler flags with the error, "‘CFString’ is not implicitly convertible to ‘String’; did you mean to use ‘as’ to explicitly convert?"

       

      if case kUTTypeImage as String as String = "" { }
      

      This line works, but it seems wrong to have to cast twice.

       

        Attachments

          Activity

            People

            Assignee:
            greg Greg Titus
            Reporter:
            nwhittaker Nathan Whittaker
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: