Skip to content

28.0-rc2 erl_syntax:revert/1 doesn't roundtrip annotations for lists #9627

Open
@jcpetruzza

Description

@jcpetruzza

Describe the bug
There is a regression in erl_syntax:revert/1: annotating the bindings on a syntax-tree and immediately reverting leads to the source position annotation for nil getting lost.

To Reproduce

-module(repro).

-export([
    run/0,
    foo/0
]).

foo() ->
  [a, b, c].

foo_syntax_tree() ->
    {ok, {_, [{abstract_code, AbsCode}]}} = beam_lib:chunks(code:which(?MODULE), [abstract_code]),
    {raw_abstract_v1, Forms} = AbsCode,
    [IsAny] = [Clause || {function, _, foo, 0, [Clause]} <- Forms],
    IsAny.

run() ->
    Original = foo_syntax_tree(),
    io:format("Original:~n~p~n", [Original]),
    Annotated = erl_syntax_lib:annotate_bindings(Original, ordsets:new()) ,
    Reverted = erl_syntax:revert(Annotated),
    io:format("Reverted:~n~p~n", [Reverted]),
    ok.
$ bin/erl
Erlang/OTP 28 [RELEASE CANDIDATE 2] [erts-15.2.3] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit:ns]

Eshell V15.2.3 (press Ctrl+G to abort, type help(). for help)
1> {ok, _} = c(repro, [debug_info]), l(repro), repro:run().
Original:
{clause,{8,1},
        [],[],
        [{cons,{9,3},
               {atom,{9,4},a},
               {cons,{9,7},
                     {atom,{9,7},b},
                     {cons,{9,10},{atom,{9,10},c},{nil,{9,11}}}}}]}
Reverted:
{clause,{8,1},
        [],[],
        [{cons,{9,3},
               {atom,{9,4},a},
               {cons,{9,7},
                     {atom,{9,7},b},
                     {cons,{9,10},{atom,{9,10},c},{nil,0}}}}]}
ok
2>

Expected behavior
In Reverted, we should see {nil, {9,11}}, instead we see {nil, 0}

Affected versions
28-rc2 (9834e60)

Metadata

Metadata

Assignees

Labels

bugIssue is reported as a bughelp wantedIssue not worked on by OTP; help wanted from the communityteam:VMAssigned to OTP team VM

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions