Cover transforms some binary comprehensions incorrectly
Alexander Burkov <[email protected]> Thu, 09 Apr 2015 10:27:36 +0000
| Newsgroups | gmane.comp.lang.erlang.bugs |
|---|---|
| Message-ID | <CAB85mbGFpbY=yL=nnip1fcJkdKkz-rDN+PV1fdMBJZ1Pc9P4Zg@mail.gmail.com> |
In some cases cover transforms binary comprehensions into non-working ones.
Please consider example below:
---cut---
-module(wrong_transform).
-compile(export_all).
good() ->
<< <<$,, X/binary>> || X <- [ <<"a">>, <<"b">> ]>>.
bad() ->
<< <<",", X/binary>> || X <- [ <<"a">>, <<"b">> ]>>.
---cut---
With disabled cover, outputs of this functions are equal, `bad() =:=
good()`. But if you do `cover:compile_beam/1` (see decompile.erl) it blows
with `badarg` in `bad/0` function. Meanwhile `good/0` works well.
I've patched a bit `cover.erl` to dump AST forms before and after
`cover:compile_beam/1` and found that for some reason it surrounds terms
inside of comprehension with `begin ... end` pattern. It is wrong in case
of list (I can't explain why, but it throws badarg, so I guess it is
definitely an issue :)
Also I will appreciate if someone explain me why we do need this cover's
trick with `begin .. end`.
Thank you!
_______________________________________________
erlang-bugs mailing list
[email protected]
http://erlang.org/mailman/listinfo/erlang-bugs
wrong_transform.after.erl
(application/octet-stream, 455 B) - not displayed
wrong_transform.after.ast
(application/octet-stream, 2.4 KB) - not displayed
wrong_transform.before.ast
(application/octet-stream, 1.5 KB) - not displayed
cover.erl.patch
(application/octet-stream, 690 B)
--- cover.original.erl 2015-04-08 16:44:25.000000000 +0300
+++ ../lib/tools/src/cover.erl 2015-04-08 16:42:33.000000000 +0300
@@ -1359,7 +1359,10 @@ do_compile_beam(Module,Beam,UserOptions)
{error,E};
{raw_abstract_v1,Code} ->
Forms0 = epp:interpret_file_attribute(Code),
+ io:format("see ~p.*.ast", [Module]),
+ file:write_file(atom_to_list(Module) ++ ".before.ast", io_lib:format("~p", [Forms0])),
{Forms,Vars} = transform(Forms0, Module),
+ file:write_file(atom_to_list(Module) ++ ".after.ast", io_lib:format("~p", [Forms])),
%% We need to recover the source from the compilation
%% info otherwise the newly compiled module will have
decompile.erl
(application/octet-stream, 552 B) - not displayed
wrong_transform.before.erl
(application/octet-stream, 184 B) - not displayed
wrong_transform.erl
(application/octet-stream, 182 B) - not displayed