2 Replies
      Latest reply: Dec 28, 2016 5:07 PM by goldsdad RSS
      goldsdad Level 4 Level 4 (580 points)

        The output from this 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 other false lines, yet the result is true. Any explanations for the last true other than a bug?