Problem:
When running the following code under Xcode 7.3 with swift 2.2, the compiler is unable to correctly infer the type of the optional:
This seems to be a bug. The minimal example is the following:
func genericMethod<T>(property: T?) {
print(T) // String
let stringNil = Optional<String>.None
print(stringNil is String?) // true (warning - always true)
print(stringNil is T?) // true
let intNil = Optional<Int>.None
print(intNil is String?) // false (warning - always fails)
print(intNil is T?) // true - BUG
}
genericMethod("")