Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Fable.Cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

* [Python] Fix `String.IndexOf`/`LastIndexOf` with `StringComparison` argument emitting it as a start-index instead of a compile error (by @repo-assist)
* [Beam] Fix `String.IndexOf`/`LastIndexOf` with `StringComparison` argument incorrectly treating the enum value as a start index

## 5.0.0-rc.6 - 2026-03-31
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 @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

* [Python] Fix `String.IndexOf`/`LastIndexOf` with `StringComparison` argument emitting it as a start-index instead of a compile error (by @repo-assist)
* [Beam] Fix `String.IndexOf`/`LastIndexOf` with `StringComparison` argument incorrectly treating the enum value as a start index

## 5.0.0-rc.12 - 2026-03-31
Expand Down
16 changes: 16 additions & 0 deletions src/Fable.Transforms/Python/Replacements.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1497,6 +1497,14 @@ let strings (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr opt
Some c,
args -> Helper.InstanceCall(c, methName, t, args, i.SignatureArgTypes, ?loc = r) |> Some
| "IndexOf", Some c, _ ->
let args =
args
|> List.filter (
function
| StringComparisonEnumValue -> false
| _ -> true
)

match args with
| [ ExprType Char ]
| [ ExprType String ]
Expand All @@ -1508,6 +1516,14 @@ let strings (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr opt
|> addErrorAndReturnNull com ctx.InlinePath r
|> Some
| "LastIndexOf", Some c, _ ->
let args =
args
|> List.filter (
function
| StringComparisonEnumValue -> false
| _ -> true
)

match args with
| [ ExprType Char ]
| [ ExprType String ] -> Helper.InstanceCall(c, "rfind", t, args, i.SignatureArgTypes, ?loc = r) |> Some
Expand Down
25 changes: 25 additions & 0 deletions tests/Python/TestString.fs
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,31 @@ let ``test String.LastIndexOf works with offset`` () =
"abcdbcebc".LastIndexOf("bc", 3)
|> equal 1

[<Fact>]
let ``test String.IndexOf with StringComparison works`` () =
"abcdbc".IndexOf("b", StringComparison.Ordinal)
|> equal 1

[<Fact>]
let ``test String.IndexOf char with StringComparison works`` () =
"abcdbc".IndexOf('b', StringComparison.Ordinal)
|> equal 1

[<Fact>]
let ``test String.IndexOf with index and StringComparison works`` () =
"abcdbc".IndexOf("b", 3, StringComparison.Ordinal)
|> equal 4

[<Fact>]
let ``test String.LastIndexOf with StringComparison works`` () =
"abcdbc".LastIndexOf("b", StringComparison.Ordinal)
|> equal 4

[<Fact>]
let ``test String.LastIndexOf with index and StringComparison works`` () =
"abcdbc".LastIndexOf("b", 3, StringComparison.Ordinal)
|> equal 1


[<Fact>]
let ``test String.IndexOfAny works`` () =
Expand Down
Loading