浏览代码

Support typed records newly exposed in OTP 19

Otherwise `lager_transform` fails after de9012628a

The error message is:

    test/pr_nested_record_test.erl: error in parse transform 'lager_transform': {function_clause,
                                                 [{lager_transform,
                                                   '-walk_ast/2-fun-0-',
                                                   [{typed_record_field,
                                                     {record_field,5,
                                                      {atom,5,field1}},
                                                     {type,5,term,[]}}],
                                                   [{file,
                                                     "src/lager_transform.erl"},
                                                    {line,62}]},
pull/321/head
Johannes Weißl 9 年前
父节点
当前提交
d35670e01a
共有 1 个文件被更改,包括 8 次插入5 次删除
  1. +8
    -5
      src/lager_transform.erl

+ 8
- 5
src/lager_transform.erl 查看文件

@ -59,16 +59,19 @@ walk_ast(Acc, [{function, Line, Name, Arity, Clauses}|T]) ->
walk_ast([{function, Line, Name, Arity,
walk_clauses([], Clauses)}|Acc], T);
walk_ast(Acc, [{attribute, _, record, {Name, Fields}}=H|T]) ->
FieldNames = lists:map(fun({record_field, _, {atom, _, FieldName}}) ->
FieldName;
({record_field, _, {atom, _, FieldName}, _Default}) ->
FieldName
end, Fields),
FieldNames = lists:map(fun record_field_name/1, Fields),
stash_record({Name, FieldNames}),
walk_ast([H|Acc], T);
walk_ast(Acc, [H|T]) ->
walk_ast([H|Acc], T).
record_field_name({record_field, _, {atom, _, FieldName}}) ->
FieldName;
record_field_name({record_field, _, {atom, _, FieldName}, _Default}) ->
FieldName;
record_field_name({typed_record_field, Field, _Type}) ->
record_field_name(Field).
walk_clauses(Acc, []) ->
lists:reverse(Acc);
walk_clauses(Acc, [{clause, Line, Arguments, Guards, Body}|T]) ->

正在加载...
取消
保存