[erlang-bugs] erl_syntax constructors too forgiving
Ulf Wiger (TN/EAB)
ulf.wiger@REDACTED
Wed Jul 25 15:04:13 CEST 2007
Lately, I've been running into crashes in syntax_tools,
whenever I try to do something interesting. The crashes
tend to occur in erl_syntax:revert/1, and often on
constructs that have been built using the erl_syntax
constructors.
The latest example is given below.
After some debugging, I've found the error.
I had called erl_syntax:application(Operator, Args)
with a non-list as Args. Since the constructor
doesn't check whether Args is in fact a list, the
crash occurs within a list comprehension clause
in revert instead. Apparently, the constructors are
forgiving, but revert/1 is not.
A few is_list/1 guards in the right places would make
life much easier. (:
BR,
Ulf W
84> A.
{application,{atom,13,np},
{tree,list,
{attr,0,[],none},
{list,[{integer,13,1}],
{tree,list,
{attr,0,[],none},
{list,[{var,0,'V73'}],none}}}}}
85> erl_syntax:revert(A).
{application,{atom,13,np},
{tree,list,
{attr,0,[],none},
{list,[{integer,13,1}],
{tree,list,
{attr,0,[],none},
{list,[{var,0,'V73'}],none}}}}}
So far, so good, but when I put a standard erl_syntax
tree node around it, it goes badly (note: in practice,
it's erl_syntax that inserts the tree wrapper).
86> erl_syntax:revert({tree,application,{attr,0,none},A}).
=ERROR REPORT==== 25-Jul-2007::14:47:03 ===
Error in process <0.316.0> with exit value:
{function_clause,[{erl_syntax,'-revert/1-lc$^1/1-1-',[{tree,list,{attr,0
,[],none},{list,[{integer,13,1}],{tree,list,{attr,0,[],none},{list,[{var
,0,'V73'}],none}}}}]},{erl_syntax,'-revert/1-lc$^0/1-0-',1},{erl_syntax,
'-revert/1-lc$^0/1-0-'...
** exited: {function_clause,
[{erl_syntax,
'-revert/1-lc$^1/1-1-',
[{tree,
list,
{attr,0,[],none},
{list,
[{integer,13,1}],
{tree,
list,
{attr,0,[],none},
{list,[{var,0,'V73'}],none}}}}]},
{erl_syntax,'-revert/1-lc$^0/1-0-',1},
{erl_syntax,'-revert/1-lc$^0/1-0-',1},
{erl_syntax,revert,1},
{erl_eval,do_apply,5},
{shell,exprs,6},
{shell,eval_loop,3}]} **
87> rr(code:which(erl_syntax)).
[application,
arity_qualifier,
attr,
attribute,
binary_field,
case_expr,
class_qualifier,
clause,
com,
comment,
function,
generator,
infix_expr,
list,
list_comp,
macro,
match_expr,
module_qualifier,
prefix_expr,
receive_expr,
record_access,
record_expr,
record_field,
record_index_expr,
rule,
size_qualifier,
tree,
try_expr,
wrapper]
88> {tree,application,{attr,0,none},A}.
#tree{
type = application,
attr = {attr,0,none},
data =
#application{
operator = {atom,13,np},
arguments =
#tree{
type = list,
attr = #attr{pos = 0,ann = [],com = none},
data =
#list{
prefix = [{integer,13,1}],
suffix =
#tree{
type = list,
attr = #attr{pos = 0,ann = [],com = none},
data = #list{prefix = [{var,0,'V73'}],suffix = none}}}}}}
More information about the erlang-bugs
mailing list