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

Optional<T>.none -> Optional<U>.none casting regression in generic context

    XMLWordPrintable

    Details

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

      Apple Swift version 5.0-dev (LLVM eb302e257f, Clang a113643bc4, Swift 646034c539)
      Target: x86_64-apple-darwin18.2.0

      Description

      In Swift 4.2 the following cast correctly succeeds:

      func test<T>(_ type: T.Type) -> T? {
        return Any?.none as? T
      }
      
      print(test(Bool?.self)) // Optional(nil)
      

      However, as discovered on the forums, in Swift 5 it incorrectly fails and prints nil instead. This does appear to be fixed on master, but we should add a test case.

        Attachments

          Activity

            People

            • Assignee:
              originaluser2 Hamish Knight
              Reporter:
              originaluser2 Hamish Knight
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: