Skip to content

[Repo Assist] fix: improve Binary type signatures and add missing tests#85

Draft
github-actions[bot] wants to merge 1 commit intomainfrom
repo-assist/improve-binary-types-tests-2026-04-8c8843be93957a8d
Draft

[Repo Assist] fix: improve Binary type signatures and add missing tests#85
github-actions[bot] wants to merge 1 commit intomainfrom
repo-assist/improve-binary-types-tests-2026-04-8c8843be93957a8d

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 This is an automated contribution from Repo Assist, an AI assistant.

What

Two complementary improvements to Fable.Beam.Binary and Fable.Beam.Erlang:

Task 5 — Coding Improvements: eliminate bare obj

Per the BINDINGS-GUIDE.md core rule ("No bare obj"), two members in Binary.fs used obj where a more precise type exists:

Before After
bin_to_list: subject: string -> obj bin_to_list: subject: string -> BeamList<int>
list_to_bin: byteList: obj -> string list_to_bin: byteList: BeamList<int> -> string

binary:bin_to_list/1 returns a list of byte integers (0–255), so BeamList<int> is the correct type. The companion list_to_bin naturally takes the same.

Erlang.listToBinary also had list: obj -> obj; corrected to list: BeamList<int> -> string (it wraps erlang:list_to_binary/1 which returns a binary).

Since [<Erase>] types have zero runtime cost, these are purely compile-time improvements — no Erlang output changes.

Task 9 — Testing Improvements: cover untested Binary functions

TestBinary.fs had no tests for 6 members of the binary module binding:

  • bin_to_list / list_to_bin / roundtrip
  • encode_unsigned / decode_unsigned
  • decode_unsigned with endianness option
  • referenced_byte_size
  • longest_common_suffix

Also added a test for Re.replaceFirstWith — the only *With variant in TestRe.fs without any coverage.

Changes

  • src/otp/Binary.fs — add open Fable.Beam.Lists; fix bin_to_list return type and list_to_bin parameter type
  • src/otp/Erlang.fs — fix listToBinary signature
  • test/TestBinary.fs — add open Fable.Beam and 8 new tests
  • test/TestRe.fs — add 1 new test for replaceFirstWith

Trade-offs

Changing list: obj to list: BeamList<int> is technically a narrowing of the public API. In practice, any caller already holding a BeamList<int> (the only sensible source) is unaffected. Callers passing a raw obj would need to add a cast — this is the desired outcome since passing arbitrary obj to list_to_bin is a bug.

Generated by Repo Assist · ● 3.5M ·

- Binary.bin_to_list: obj -> BeamList<int> (byte list, not opaque obj)
- Binary.list_to_bin: obj -> BeamList<int> parameter (no bare obj)
- Erlang.listToBinary: obj params -> BeamList<int>/string (precise types)
- Add 8 new tests for previously-untested Binary functions:
  bin_to_list, list_to_bin, roundtrip, encode/decode_unsigned,
  little-endian decode, referenced_byte_size, longest_common_suffix
- Add Re.replaceFirstWith test (was the only *With variant without coverage)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants