[erlang-patches] Bit string generators, unsized binaries, modules and the REPL

Anthony Ramine <>
Sun Mar 31 16:22:37 CEST 2013


People on IRC noticed a difference between compiled modules and the REPL in how some binary generators are handled.


$ cat unsized_bin_gen_pat.erl
t() -> << <<X,Tail/binary>> || <<X,Tail/binary>> <= <<1,2,3>> >>.
$ erlc unsized_bin_gen_pat.erl
$ erl

1> % compiled
1> unsized_bin_gen_pat:t().
2> % evaluated
2> << <<X,Tail/binary>> || <<X,Tail/binary>> <= <<1,2,3>> >>.

I don't think the compiler should be changed to behave like the REPL, nor I think the REPL should be changed to behave like the compiler. Instead, I think an unsized binary tail in the pattern of a binary generator does not make sense, and this should happen:

$ erlc unsized_bin_gen_pat.erl
unsized_bin_gen_pat.erl:3: binary fields without size are not allowed in patterns of bit string generators

This patch implements this new error and simplifies how v3_core works with forbidden unsized tail segments in patterns of bit string generators.

	git fetch https://github.com/nox/otp illegal-bitstring-gen-pattern


Looking at the commit 5daa001 by Björn Gustavsson "Don't generate multiple tail segments in binary matching", this patch will probably by rejected as it seems the compiler behaves as wanted by the OTP team. If this is indeed the case, erl_eval should be fixed.


Anthony Ramine

More information about the erlang-patches mailing list