Skip to content

Instantly share code, notes, and snippets.

@xjia1
Last active January 3, 2016 13:49
Show Gist options
  • Save xjia1/8471800 to your computer and use it in GitHub Desktop.
Save xjia1/8471800 to your computer and use it in GitHub Desktop.
$ erlc zt.erl
$ erlc -pa . z.erl
z.erl:none: internal error in lint_module;
crash reason: {badarg,[{erl_scan,set_attr,
                                 [line,function,#Fun<erl_lint.9.103090672>],
                                 [{file,"erl_scan.erl"},{line,418}]},
                       {erl_lint,modify_line1,2,
                                 [{file,"erl_lint.erl"},{line,3352}]},
                       {erl_lint,eval_file_attr,2,
                                 [{file,"erl_lint.erl"},{line,650}]},
                       {erl_lint,eval_file_attr,2,
                                 [{file,"erl_lint.erl"},{line,651}]},
                       {erl_lint,eval_file_attr,2,
                                 [{file,"erl_lint.erl"},{line,648}]},
                       {erl_lint,forms,2,[{file,"erl_lint.erl"},{line,608}]},
                       {erl_lint,module,3,[{file,"erl_lint.erl"},{line,472}]},
                       {compile,lint_module,1,
                                [{file,"compile.erl"},{line,912}]}]}

It is not a bug.

"AST" in parse_transform/2 is a list of abstract forms but the output of erl_syntax_lib:mapfold/3 is a syntax tree (namely, that "T1"), that's why it throws some errors because parse_transform/2 should return a list of abstract forms. You can give a list of syntax trees to erl_syntax:revert_forms/1 to get a list of abstract forms.

-- Sina Samavati

Finally I understand this and use erl_syntax:revert instead.

-module(z).
-compile({parse_transform, zt}).
-export([f/1]).
f(_) -> z.
-module(zt).
-export([parse_transform/2]).
parse_transform(AST, _Options) ->
[parse(T) || T <- AST].
parse({function, _, _, _, _} = T) ->
case erl_syntax_lib:mapfold(fun foobar/2, something, T) of
{T1, _} -> T1;
_ -> T
end;
parse(T) -> T.
foobar(T, S) -> {erl_syntax:revert(T), S}.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment