Skip to content

Commit

Permalink
Merge pull request #3602 from fable-compiler/fix/python_toString
Browse files Browse the repository at this point in the history
Fix #3601: Fix calling `value.ToString(CultureInfo.InvariantCulture)`
  • Loading branch information
MangelMaxime authored Nov 20, 2023
2 parents 5d6eeed + 7d76685 commit 13ed2a1
Show file tree
Hide file tree
Showing 3 changed files with 8 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 @@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* Fixed char to string type regression with binary operator (by @dbrattli)
* Fix `DateTime(..., DateTimeKind.Local).ToString("O")` (by @MangelMaxime)
* Fix calling `value.ToString(CultureInfo.InvariantCulture)` (by @MangelMaxime)

## 4.5.0 - 2023-11-07

Expand Down
2 changes: 1 addition & 1 deletion src/Fable.Transforms/Python/Replacements.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2245,7 +2245,7 @@ let parseNum (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr op
Helper.LibCall(com, "string", "format", t, [ format; thisArg.Value ], [ format.Type; thisArg.Value.Type ], ?loc = r)
|> Some
| "ToString", _ ->
Helper.GlobalCall("String", String, [ thisArg.Value ], ?loc = r)
Helper.GlobalCall("str", String, [ thisArg.Value ], ?loc = r)
|> Some
| _ -> None

Expand Down
6 changes: 6 additions & 0 deletions tests/Python/TestString.fs
Original file line number Diff line number Diff line change
Expand Up @@ -888,3 +888,9 @@ let ``test Can create FormattableString`` () =
[<Fact>]
let ``test printing strings with unicode characters`` () =
printfn "🚀 printing unicode ..."

[<Fact>]
let ``test calling ToString(CultureInfo.InvariantCulture) works`` () =
(1).ToString(CultureInfo.InvariantCulture) |> equal "1"
(7923209L).ToString(CultureInfo.InvariantCulture) |> equal "7923209"
(7923209UL).ToString(CultureInfo.InvariantCulture) |> equal "7923209"

0 comments on commit 13ed2a1

Please sign in to comment.