Skip to content

Commit

Permalink
[Python] Fix #3998: PhysicalEquality (#4034)
Browse files Browse the repository at this point in the history
* [Python] Fix #3998: PhysicalEquality

* udpate changelog entry

---------

Co-authored-by: Maxime Mangel <[email protected]>
  • Loading branch information
alfonsogarciacaro and MangelMaxime authored Feb 9, 2025
1 parent 798684a commit 38fdf45
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Fable.Cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

* [JS/TS] - Fix anonymous record printing (#4029) (by @alfonsogarciacaro)
* [Python] - Fix #3998: PhysicalEquality (by @alfonsogarciacaro)

## 5.0.0-alpha.9 - 2025-01-28

Expand Down
1 change: 1 addition & 0 deletions src/Fable.Compiler/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

* [JS/TS] - Fix anonymous record printing (#4029) (by @alfonsogarciacaro)
* [Python] - Fix #3998: PhysicalEquality (by @alfonsogarciacaro)

## 5.0.0-alpha.9 - 2025-01-28

Expand Down
3 changes: 2 additions & 1 deletion src/Fable.Transforms/Python/Replacements.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2269,7 +2269,8 @@ let languagePrimitives (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisAr
[ comp; left; right ] ->
Helper.InstanceCall(comp, "Equals", t, [ left; right ], i.SignatureArgTypes, ?loc = r)
|> Some
| ("PhysicalEquality" | "PhysicalEqualityIntrinsic"), [ left; right ] -> makeEqOp r left right BinaryEqual |> Some
| ("PhysicalEquality" | "PhysicalEqualityIntrinsic"), [ left; right ] ->
makeEqOpStrict r left right BinaryEqual |> Some
| ("PhysicalHash" | "PhysicalHashIntrinsic"), [ arg ] ->
Helper.LibCall(com, "util", "physicalHash", Int32.Number, [ arg ], ?loc = r)
|> Some
Expand Down
1 change: 1 addition & 0 deletions src/Fable.Transforms/Replacements.Util.fs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ let withTag tag =
function
| Call(e, i, t, r) -> Call(e, { i with Tags = tag :: i.Tags }, t, r)
| Get(e, FieldGet i, t, r) -> Get(e, FieldGet { i with Tags = tag :: i.Tags }, t, r)
| Operation(op, tags, t, r) -> Operation(op, tag :: tags, t, r)
| e -> e

let getTags =
Expand Down
10 changes: 10 additions & 0 deletions tests/Python/TestComparison.fs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ type Status =
type MyClass(v) =
member val Value: int = v with get, set

[<Fact>]
let ``test PhysicalEquality works`` () = // See #3998
let r1 = ResizeArray([1; 2])
let r2 = ResizeArray([1; 2])
let r3 = r1

LanguagePrimitives.PhysicalEquality r1 r2 |> equal false
LanguagePrimitives.PhysicalEquality r2 r2 |> equal true
LanguagePrimitives.PhysicalEquality r3 r1 |> equal true

[<Fact>]
let ``test Typed array equality works`` () =
let xs1 = [| 1; 2; 3 |]
Expand Down

0 comments on commit 38fdf45

Please sign in to comment.