ex2ms
ex2ms copied to clipboard
Adding support for `binary_part`
Hello! Thanks for contributing this repo.
I'm currently trying to add support for binary_part as it is allowed as a guard in both erlang and elixir.
Adding :binary_part to @extra_guard_functions I expected the following test to work
test "binary_part" do
prefix = "1234"
ms =
fun do
bid when binary_part(bid, 0, 4) == ^prefix -> bid
end
assert ms == [{:"$1", [{:==, {:binary_part, :"$1", 0, 4}, {:const, prefix}}], [:"$1"]}]
assert {:ok, "12345"} == :ets.test_ms("12345", ms)
end
But I am getting the following output:
1) test binary_part (Ex2msTest)
test/ex2ms_test.exs:319
Assertion with == failed
code: assert {:ok, "12345"} == :ets.test_ms("12345", ms)
left: {:ok, "12345"}
right: {:error, [error: 'Function binary_part/3 does_not_exist.']}
stacktrace:
test/ex2ms_test.exs:328: (test)
Which seemingly means that :ets.test_ms cannot lookup erlang:binary_part/3 properly. Looking at https://github.com/erlang/otp/blob/master/erts/emulator/beam/bif.tab it appears that it's defined as ubif erlang:binary_part/3 and also as bif binary:part/3 binary_binary_part3. I'm struggling to understand why it's failing to lookup the BIF here - I tried with other ubif definitions, but they seem to work, like abs/1.
Any ideas? I was hoping to put up a PR
Thanks,
JD
Sorry, I don't know why it doesn't work. I would suggest checking with OTP devs why this doesn't seem to work as expected.
Ok, sounds good. It was worth a shot. I'll try to follow up there. I'll use this issue as reference.