fix(beam): handle string binaries in Seq enumerator#4591
Merged
Conversation
F# strings are seq<char> by language definition, but Fable.Beam lowers them to Erlang binaries. fable_utils:get_enumerator/1 had no clause for binaries, so the fallback path wrapped the binary into a single-element list — the enumerator then handed the whole binary back as one "char", crashing later code paths (e.g. <<C/utf8>> in `string c`). Add a binary clause that converts to a Unicode codepoint list, matching the existing to_list/1 handling. Repro: "Hello" |> Seq.mapi (fun _ c -> string c) |> String.concat "" Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
badargcrash when applyingSeq.Xoperations (e.g.Seq.mapi,Seq.map,Seq.toList) to a string on the BEAM target.seq<char>by language definition, but Fable.Beam lowers them to Erlang binaries.fable_utils:get_enumerator/1had no clause for binaries, so the fallback path (lists:flatten([Other])) wrapped the binary into a single-element list — the enumerator then handed the whole binary back as one "char", crashing later code paths (e.g.<<C/utf8>>fromstring c).to_list/1handling.Minimal repro
Stack trace before fix
Test plan
"Hello"after."über"enumerates as 4 codepoints (verified raw output<<"ü-b-e-r">>, 8 bytes), not 5 bytes.tests/Beam/StringTests.fscoveringSeq.mapi,Seq.map,Seq.toList,Seq.lengthover strings.🤖 Generated with Claude Code