-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Description
Description
Heterogeneous equality and comparison operators were added as part of SE-0104.
However, this led to an issue during comparisons with an integer literal where heterogeneous comparison with an Int is preferred over homogeneous comparison, as reported in SR-4984. This issue was addressed by @moiseev (in #13830) by adding overloads of these operators with same-type parameters to concrete integer types (which would be preferred).
There has been a regression in Swift 5.0 which leads to the problem resurfacing.
Reproduction
let x = Int32.min == 1 << 31
let y = Int32.min != 1 << 31
let z = !(Int32.min == 1 << 31)
print(x, y, z)Expected behavior
In Swift 4.2, this produces the expected result: true false false.
As of Swift 5.0 and to this day, it produces the unexpected result: true true false.
Environment
Apple Swift version 5.9 (swiftlang-5.9.0.128.108 clang-1500.0.40.1)
Target: arm64-apple-darwin22.6.0
Additional information
https://forums.swift.org/t/nolocks-with-int32-inequality-check/68625