Skip to content

The equality comparison operator == is producing incorrect results for KeyPaths on Swift 6.0 Development Snapshots. #73554

@fibrechannelscsi

Description

@fibrechannelscsi

Description

There are cases when the equality comparison operator == is returning true when it ought to return false. Here, both sides involve KeyPaths, but the KeyPaths themselves are different.

Reproduction

Run the below code (built either in Debug or Release mode) with a recent Swift 6.0 Development Snapshot (2024-04-30 tested).

  struct O {var a: Int}
  struct I {var b: Int}
  print(\I.b == \O.a)

Expected behavior

The above code should print false.

Environment

Swift Development Snapshot 6.0 (2024-04-29a and 2024-04-30a) are affected.
If using Xcode, one can create a new xcodeproj, paste in the above code, switch to a 6.0-branch toolchain, and run.
This problem also occurs in Ubuntu 20 with an x86 machine.
Note that when running the executable on a MacOS terminal window, the executable itself ought to be using the libswiftCore.dylib corresponding to a 6.0-based toolchain, rather than the default system one.

Additional information

None of the nightly toolchains (i.e, 2024-05-01a) nor anything on the 5.10 branch appears to be affected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    AnyKeyPathArea → standard library: The `AnyKeyPath` typeEquatableArea → standard library: The `Equatable` protocolbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.key pathsFeature: key paths (both native and Objective-C)standard libraryArea: Standard library umbrellaswift 6.0unexpected behaviorBug: Unexpected behavior or incorrect output

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions