[erlang-bugs] erl_syntax:type/1 fails for binary comprehensions

Matthias Radestock <>
Sat Apr 14 08:44:10 CEST 2007

Matthias Radestock <> writes:

> The code in erl_syntax:type/1 is missing a case for the bc (binary
> comprehension) nodes produced by erl_parse.

Here's an example demonstrating this problem:

(fun(Str) ->
         {ok, Tokens, _} = erl_scan:string(Str),
         {ok, [Expr]} = erl_parse:parse_exprs(Tokens),
         erl_prettypr:format(Expr) end)
("<< <<X:1>> || X <- [] >>.").
** exited: {{badarg,
             {shell,eval_loop,3}]} **

This, of course, isn't the only place in erl_syntax where support for
binary comprehensions is missing. There's also revert_root/1,
subtrees/1, and make_tree/3

Plus there should be various constructor/accessor functions analogous to
list_comp/2, list_comp_body/1, list_comp_template/1.

Then there are a whole bunch of modules that call into erl_syntax and
are also lacking cases for binary comprehension. For example
erl_prettypr and erl_tidy.

AFAIK binary comprehensions were introduced in R11B-0, which was
released on May 17, 2006. I am somewhat surprised that these bugs have
managed to slip through the net for almost a year. Granted, binary
comprehensions aren't that common, since they are a new feature. In
fact, it appears that the OTP sources only contain one use - in
eval_bits:convert_list/1 - and that was only introduced in R11B-4.

There is an easy way to spot this and other potential bugs in erl_syntax
and friends: run erl_tidy on the OTP sources. Perhaps that should be
added to the OTP test suite?



More information about the erlang-bugs mailing list