Skip to content

Regression in inequality operator != overload resolution #70041

@xwu

Description

@xwu

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.regressiontriage neededThis issue needs more specific labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions