Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binary comprehension formatting results in broken code #342

Open
onno-vos-dev opened this issue Mar 17, 2023 · 0 comments
Open

Binary comprehension formatting results in broken code #342

onno-vos-dev opened this issue Mar 17, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@onno-vos-dev
Copy link

Describe the bug
Trying to format a binary comprehension such as:

<< (integer_to_binary(I)) || <<I>> <= <<"12345">> >>.

results in formatted code such as AFTER having produced an error for it:

<< integer_to_binary(I) || <<I>> <= <<"12345">> >>.

which is both incorrect and doesn't compile due to:

===> Compiling src/binary_comprehension_bad_format.erl failed
src/binary_comprehension_bad_format.erl:6:23: syntax error before: '('

src/binary_comprehension_bad_format.erl:3:2: function bad_format/0 undefined

To Reproduce

-module(binary_comprehension_bad_format).

-export([bad_format/0]).

bad_format() ->
  << (integer_to_binary(I)) || <<I>> <= <<"12345">> >>.

Steps to reproduce the behavior.

Expected behavior
Binary comprehensions can be formatted correctly

Rebar3 Log

===> Formatting "src/binary_comprehension_bad_format.erl" with #{module =>
                                                                            default_formatter,
                                                                        opts =>
                                                                            #{action =>
                                                                                  format,
                                                                              break_indent =>
                                                                                  2,
                                                                              output_dir =>
                                                                                  current,
                                                                              paper =>
                                                                                  100,
                                                                              parse_macro_definitions =>
                                                                                  true,
                                                                              ribbon =>
                                                                                  100,
                                                                              truncate_strings =>
                                                                                  true},
                                                                        state =>
                                                                            nostate}
===> Error parsing files: {modified_ast,
                                     "src/binary_comprehension_bad_format.erl",
                                     "src/binary_comprehension_bad_format.erl"}
Stack: [{rebar3_ast_formatter,format,3,
                              [{file,"/home/onnovos/src/github/aws-beam/aws-erlang/_build/default/plugins/rebar3_format/src/rebar3_ast_formatter.erl"},
                               {line,40}]},
        {rebar3_format_prv,'-format_files/2-fun-0-',2,
                           [{file,"/home/onnovos/src/github/aws-beam/aws-erlang/_build/default/plugins/rebar3_format/src/rebar3_format_prv.erl"},
                            {line,148}]},
        {lists,'-filter/2-lc$^0/1-0-',2,[{file,"lists.erl"},{line,1383}]},
        {rebar3_format_prv,format_files,2,
                           [{file,"/home/onnovos/src/github/aws-beam/aws-erlang/_build/default/plugins/rebar3_format/src/rebar3_format_prv.erl"},
                            {line,146}]},
        {rebar3_format_prv,do,1,
                           [{file,"/home/onnovos/src/github/aws-beam/aws-erlang/_build/default/plugins/rebar3_format/src/rebar3_format_prv.erl"},
                            {line,52}]},
        {rebar_core,do,2,
                    [{file,"/home/runner/work/rebar3/rebar3/apps/rebar/src/rebar_core.erl"},
                     {line,155}]},
        {rebar3,run_aux,2,
                [{file,"/home/runner/work/rebar3/rebar3/apps/rebar/src/rebar3.erl"},
                 {line,193}]},
        {rebar3,main,1,
                [{file,"/home/runner/work/rebar3/rebar3/apps/rebar/src/rebar3.erl"},
                 {line,66}]}]
=ERROR REPORT==== 17-Mar-2023::19:54:21.602021 ===
    added: [{tree,no,
                  {attr,no,[],none},
                  "bad_format( ) -> << integer_to_binary( I ) || << I >> <= << \"12345\" >> >> .\n"}]
    modified_ast: src/binary_comprehension_bad_format.erl
    removed: [{function,no,bad_format,0,
               [{clause,no,[],[],
                 [{bc,no,
                   {call,no,{atom,no,integer_to_binary},[{var,no,'I'}]},
                   [{b_generate,no,
                     {bin,no,[{bin_element,no,{var,no,'I'},default,default}]},
                     {bin,no,
                      [{bin_element,no,
                        {string,no,"12345"},
                        default,default}]}}]}]}]}]
===> Unknown Formatting Error: {modified_ast,
                              "src/binary_comprehension_bad_format.erl",
                              "src/binary_comprehension_bad_format.erl"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant