True?

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?

Accepted Reply

You should definitely file a bug about this one. Please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Replies

You should definitely file a bug about this one. Please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Thanks!


https://bugs.swift.org/browse/SR-3505