AdRoll / rebar3_format

Erlang Formatter for Rebar3
https://tech.nextroll.com/blog/dev/2020/02/25/erlang-rebar3-format.html
MIT License
109 stars 21 forks source link

The sort_arity_qualifiers option seems to crash sometimes when dealing with export_type qualifiers #349

Closed pablocostass closed 1 year ago

pablocostass commented 1 year ago

Describe the bug As the title says, the formatter currently crashes sometimes when formatting modules that include the -export_type(([...]). qualifier. It's funny because #328 included examples with it 🤷🏻

To Reproduce

Take this very minimal module and format it

-module(abc).

-format #{sort_arity_qualifiers => true}.

-type wololo() :: ok.
-type ninjalui() :: ok.

-export_type([wololo/0, ninjalui/0]).

Expected behavior The export type list should have ben formatted as -export_type([ninjalui/0, wololo/0]). but instead the formatter crashes as follows:

➜ rebar3 format --files /tmp/abc.erl
===> Analyzing applications...
===> Compiling rebar3_format
===> Error parsing files: {modified_ast,"/tmp/abc.erl","/tmp/abc.erl"}
Stack: [{rebar3_ast_formatter,compare_asts_if_sort_arity_qualifiers,5,
                              [{file,"/Users/pablocostassanchez/code/other/rebar3_format/src/rebar3_ast_formatter.erl"},
                               {line,75}]},
        {rebar3_ast_formatter,format,3,
                              [{file,"/Users/pablocostassanchez/code/other/rebar3_format/src/rebar3_ast_formatter.erl"},
                               {line,37}]},
        {rebar3_format_prv,'-format_files/2-fun-0-',2,
                           [{file,"/Users/pablocostassanchez/code/other/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,"/Users/pablocostassanchez/code/other/rebar3_format/src/rebar3_format_prv.erl"},
                            {line,146}]},
        {rebar3_format_prv,do,1,
                           [{file,"/Users/pablocostassanchez/code/other/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}]}]
=ERROR REPORT==== 1-Aug-2023::09:54:30.028331 ===
    added: [{attribute,no,export_type,[{ninjalui,no},{wololo,no}]}]
    modified_ast: /tmp/abc.erl
    removed: [{attribute,no,export_type,[{wololo,no},{ninjalui,no}]}]
===> Unknown Formatting Error: {modified_ast,"/tmp/abc.erl","/tmp/abc.erl"}

Rebar3 Log I am skipping this bit because I have the fix ready