[bug] syntax_tool-1.6.5, injury data in erl_syntax_lib:map()
Alexander Demidenko
alex.demidenko@REDACTED
Fri Jan 28 08:07:39 CET 2011
Hi!
I have fix for old bug. Please confirm.
I believe that the behavior of the functions map() and
fold() must be coordinated.
Otherwise it leads to errors when processing ast-tree by parse_transform.
Test on Erlang R13B04 (erts-5.7.5) and Erlang R13B01 (erts-5.7.2)
erl_syntax.diff
2264,2267c2264,2267
< {nil, _} ->
< none; % no interesting information is lost
< _ ->
< Tail
---
> %% {nil, _} ->
> %% none; % no interesting information is lost
> _ ->
> Tail
On Tue, Jun 29, 2010 at 7:27 PM, Alexander Demidenko <
alex.demidenko@REDACTED> wrote:
> Hi,
>
> Try to show on a synthetic example:
>
> I have some source data:
> 1> X = {function,34,handle_event,2, [{clause,34,
> [{var,34,'_'},{var,34,'_'}],[], [{cons,35,{tuple,35,[]},{nil,36}}]}]}.
> {function,34,handle_event,2,
> [{clause,34,
> [{var,34,'_'},{var,34,'_'}],
> [],
> [{cons,35,{tuple,35,[]},{nil,36}}]}]}
>
> Now, I will try to traverse the data via erl_syntax_lib:map()
>
> 2> erl_syntax_lib:map(fun (El) -> io:format("~p~n",
> [erl_syntax:revert(El)]), El end, X).
> {atom,34,handle_event}
> {var,34,'_'}
> {var,34,'_'}
> {tuple,35,[]}
> {cons,35,{tuple,35,[]},{nil,35}}
>
> {clause,34,[{var,34,'_'},{var,34,'_'}],[],[{cons,35,{tuple,35,[]},{nil,35}}]}
> {function,34,handle_event,2,
> [{clause,34,
> [{var,34,'_'},{var,34,'_'}],
> [],
> [{cons,35,{tuple,35,[]},{nil,35}}]}]}
> {tree,function,
> {attr,34,[],none},
> {function,{tree,atom,{attr,34,[],none},handle_event},
> [{tree,clause,
> {attr,34,[],none},
> {clause,[{var,34,'_'},{var,34,'_'}],
> none,
> [{tree,list,
> {attr,35,[],none},
> {list,[{tuple,35,[]}],none}}]}}]}}
>
>
> Ops, erl_syntax_lib vodoo magic, make unexpected change original
> {nil,36} to {nil,35}
> To test, make control measurements via erl_syntax_lib:fold()
>
> 3> erl_syntax_lib:fold(fun (El, Acc) -> io:format("~p~n", [El]) end, [],
> X).
> {tree,atom,{attr,34,[],none},handle_event}
> {var,34,'_'}
> {var,34,'_'}
> {tuple,35,[]}
> {cons,35,{tuple,35,[]},{nil,36}}
>
> {clause,34,[{var,34,'_'},{var,34,'_'}],[],[{cons,35,{tuple,35,[]},{nil,36}}]}
> {function,34,handle_event,2,
> [{clause,34,
> [{var,34,'_'},{var,34,'_'}],
> [],
> [{cons,35,{tuple,35,[]},{nil,36}}]}]}
> ok
>
> Unlike map(), fold() working correctly.
>
>
> PS Test on Erlang R13B04 (erts-5.7.5) and Erlang R13B01 (erts-5.7.2)
> with same results
>
> --
> ---------------------------------------------
> With best regards,
> Alexander.
>
--
---------------------------------------------
With best regards,
Alexander.
More information about the erlang-bugs
mailing list