Skip to content

Commit 38fdf45

Browse files
[Python] Fix #3998: PhysicalEquality (#4034)
* [Python] Fix #3998: PhysicalEquality * udpate changelog entry --------- Co-authored-by: Maxime Mangel <[email protected]>
1 parent 798684a commit 38fdf45

File tree

5 files changed

+15
-1
lines changed

5 files changed

+15
-1
lines changed

src/Fable.Cli/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
### Fixed
1717

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

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

src/Fable.Compiler/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
### Fixed
1717

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

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

src/Fable.Transforms/Python/Replacements.fs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2269,7 +2269,8 @@ let languagePrimitives (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisAr
22692269
[ comp; left; right ] ->
22702270
Helper.InstanceCall(comp, "Equals", t, [ left; right ], i.SignatureArgTypes, ?loc = r)
22712271
|> Some
2272-
| ("PhysicalEquality" | "PhysicalEqualityIntrinsic"), [ left; right ] -> makeEqOp r left right BinaryEqual |> Some
2272+
| ("PhysicalEquality" | "PhysicalEqualityIntrinsic"), [ left; right ] ->
2273+
makeEqOpStrict r left right BinaryEqual |> Some
22732274
| ("PhysicalHash" | "PhysicalHashIntrinsic"), [ arg ] ->
22742275
Helper.LibCall(com, "util", "physicalHash", Int32.Number, [ arg ], ?loc = r)
22752276
|> Some

src/Fable.Transforms/Replacements.Util.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ let withTag tag =
179179
function
180180
| Call(e, i, t, r) -> Call(e, { i with Tags = tag :: i.Tags }, t, r)
181181
| Get(e, FieldGet i, t, r) -> Get(e, FieldGet { i with Tags = tag :: i.Tags }, t, r)
182+
| Operation(op, tags, t, r) -> Operation(op, tag :: tags, t, r)
182183
| e -> e
183184

184185
let getTags =

tests/Python/TestComparison.fs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ type Status =
6969
type MyClass(v) =
7070
member val Value: int = v with get, set
7171

72+
[<Fact>]
73+
let ``test PhysicalEquality works`` () = // See #3998
74+
let r1 = ResizeArray([1; 2])
75+
let r2 = ResizeArray([1; 2])
76+
let r3 = r1
77+
78+
LanguagePrimitives.PhysicalEquality r1 r2 |> equal false
79+
LanguagePrimitives.PhysicalEquality r2 r2 |> equal true
80+
LanguagePrimitives.PhysicalEquality r3 r1 |> equal true
81+
7282
[<Fact>]
7383
let ``test Typed array equality works`` () =
7484
let xs1 = [| 1; 2; 3 |]

0 commit comments

Comments
 (0)