Skip to content

[Repo Assist] [Beam] Fix String.IndexOf/LastIndexOf with StringComparison argument#4470

Merged
dbrattli merged 2 commits intomainfrom
repo-assist/fix-beam-indexof-stringcomparison-20260401-00f2663-72806ee6415a9e97
Apr 2, 2026
Merged

[Repo Assist] [Beam] Fix String.IndexOf/LastIndexOf with StringComparison argument#4470
dbrattli merged 2 commits intomainfrom
repo-assist/fix-beam-indexof-stringcomparison-20260401-00f2663-72806ee6415a9e97

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions bot commented Apr 1, 2026

🤖 This is an automated draft PR created by Repo Assist.

Summary

  • Bug: str.IndexOf(sub, StringComparison.Ordinal) in the Beam target was matching the generic [ sub; startIdx ] pattern. The StringComparison enum integer value (e.g. 4 for Ordinal) was being passed as a start index to fable_string:index_of/3, producing wrong results.
  • Fix: Add StringComparisonEnumValue-specific patterns for IndexOf and LastIndexOf before the generic two-arg patterns, so the StringComparison argument is stripped (as in the JS/TS target) and only the substring (and optional start index) is passed to the Erlang library function.
  • Tests: Adds four new tests to tests/Beam/StringTests.fs, mirroring the existing JS tests for this overload.

Root Cause

Pattern matching in Beam/Replacements.fs did not distinguish between startIdx: int and StringComparison: enum when both are passed as the second argument to IndexOf/LastIndexOf. F# pattern matching uses first-match-wins, so the [ sub; StringComparisonEnumValue ] patterns must appear before the [ sub; startIdx ] wildcard patterns.

Limitations

Like the JS/TS target, this fix does not implement case-insensitive comparison for StringComparison.OrdinalIgnoreCase — it strips the comparison argument and uses Beam's default binary (ordinal) comparison. This matches the existing behavior of all other Fable targets.

Test plan

  • Beam tests pass: ./build.sh test beam
  • No regressions in other targets

Generated by Repo Assist

Note

🔒 Integrity filtering filtered 67 items

Integrity filtering activated and filtered the following items during workflow execution.
This happens when a tool call accesses a resource that does not meet the required integrity or secrecy level of the workflow.

Generated by Repo Assist ·

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@346204513ecfa08b81566450d7d599556807389f

Without this fix, calling str.IndexOf(sub, StringComparison.Ordinal)
would match the generic [ sub; startIdx ] pattern and incorrectly pass
the enum integer value (e.g. 4 for Ordinal) as a start index, producing
wrong results.

The fix adds StringComparison-specific patterns that strip the enum
argument before the generic [ sub; startIdx ] pattern, aligning Beam
with the existing JS/TS behavior (which also strips StringComparison and
uses native ordinal comparison).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions github-actions bot added automation Automated changes repo-assist Created by Repo Assist labels Apr 1, 2026
@dbrattli dbrattli marked this pull request as ready for review April 1, 2026 04:42
…d approach

Consolidate 8 separate match arms into 2 using List.filter to strip
StringComparison args, matching the JS/TS target's approach. Also covers
Char + StringComparison overloads that were previously unhandled.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@dbrattli dbrattli merged commit 7139cf3 into main Apr 2, 2026
23 checks passed
@dbrattli dbrattli deleted the repo-assist/fix-beam-indexof-stringcomparison-20260401-00f2663-72806ee6415a9e97 branch April 2, 2026 07:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automation Automated changes repo-assist Created by Repo Assist

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant