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

Optional of a wrapped type with value nil is incorrectly considered to be an Optional of another wrapped type

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Done
    • Component/s: Standard Library
    • Labels:
    • Environment:

      OS X 10.11.6 (15G1212)
      Xcode 8.2 (8C38)
      IBM Swift Sandbox - Swift Ver. 3.0.2 (Release) - Platform: Linux (x86_64)

      Description

      The output from the following code is reasonable to me except for the last line producing "true".

      enum Foo<T> {  
          case some(T)  
          case none  
      }  
        
      print(  Foo<Int>.some(3) is Foo<Int>               ) // output: true  
      print(  Foo<Int>.some(3) is Foo<String>            ) // output: false  
        
      print(  Foo<Int>.none is Foo<Int>                  ) // output: true  
      print(  Foo<Int>.none is Foo<String>               ) // output: false  
        
      print(  Optional<Int>.some(3) is Optional<Int>     ) // output: true  
      print(  Optional<Int>.some(3) is Optional<String>  ) // output: false  
        
      print(  Optional<Int>.none is Optional<Int>        ) // output: true  
      print(  Optional<Int>.none is Optional<String>     ) // output: true  
      
      

      The compiler even issues warning "Cast from 'Optional<Int>' to unrelated type 'Optional<String>' always fails" for the last line, as it does for the lines producing "false", yet the result is "true".

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              slavapestov Slava Pestov
              Reporter:
              goldsdad Owen Roberts
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: