I played a little with this. Here is a minimal example:
struct Foo {
enum Enum {
case A
case B
case C(Int)
}
}
func ==(lhs: Foo.Enum, rhs: Foo.Enum) -> Bool {
print("comparing \(lhs) == \(rhs) -> ", terminator: "")
switch(lhs, rhs) {
case (.A, .A):
return true
case (.B,.B):
return true
default:
return false
}
}
func test() {
print( Foo.Enum.A == .B)
print([ Foo.Enum.A ][0] == .B)
print([ Foo.Enum.A ].first! == .B)
for itemType in [ Foo.Enum.A ] { print(itemType == .B) }
}
test()
In-Onone builds this print, expected four times true. In optimized lines, it prints ...
comparing A == B -> false
comparing A == B -> false
comparing A == B -> true
comparing A == B -> true
The error disappears when:
- The test is performed in the external area (not in function)
- Instead of an operator
==
, a normal function is used, - Enumeration is not nested in another type
case C
print
switch
Xcode 7.1. bugreport.apple.com