[erlang-bugs] Cover transforms some binary comprehensions incorrectly

Alexander Burkov a.p.burkov@REDACTED
Thu Apr 9 12:27:36 CEST 2015


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!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20150409/b640dde8/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: wrong_transform.after.erl
Type: application/octet-stream
Size: 455 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20150409/b640dde8/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: wrong_transform.after.ast
Type: application/octet-stream
Size: 2478 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20150409/b640dde8/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: wrong_transform.before.ast
Type: application/octet-stream
Size: 1521 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20150409/b640dde8/attachment-0002.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cover.erl.patch
Type: application/octet-stream
Size: 690 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20150409/b640dde8/attachment-0003.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: decompile.erl
Type: application/octet-stream
Size: 552 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20150409/b640dde8/attachment-0004.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: wrong_transform.before.erl
Type: application/octet-stream
Size: 184 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20150409/b640dde8/attachment-0005.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: wrong_transform.erl
Type: application/octet-stream
Size: 182 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20150409/b640dde8/attachment-0006.obj>


More information about the erlang-bugs mailing list