Kaynağa Gözat

Work around functions not found in source

For parameterized modules, the beam code will have a compiler
generated new/1 and instance/1 function.

If while checking the beam, xref detects one of those is unused, the
rebars xref wrapper will try to find the location of the definition of
that function in the source code for the module (to give a more
specific warning to the user). Since the function was generated by the
compiler it does not actually exist in the source, and rebar crashes
at that stage. This patch works around that issue.
pull/3/head
Fabian Linzberger 13 yıl önce
işlemeyi yapan: Tuncer Ayaz
ebeveyn
işleme
176ec0e71e
1 değiştirilmiş dosya ile 11 ekleme ve 5 silme
  1. +11
    -5
      src/rebar_xref.erl

+ 11
- 5
src/rebar_xref.erl Dosyayı Görüntüle

@ -188,8 +188,14 @@ find_mfa_source({M, F, A}) ->
%% Extract the original source filename from the abstract code
[{attribute, 1, file, {Source, _}} | _] = Code,
%% Extract the line number for a given function def
[{function, Line, F, _, _}] = [E || E <- Code,
safe_element(1, E) == function,
safe_element(3, E) == F,
safe_element(4, E) == A],
{Source, Line}.
Fn = [E || E <- Code,
safe_element(1, E) == function,
safe_element(3, E) == F,
safe_element(4, E) == A],
case Fn of
[{function, Line, F, _, _}] -> {Source, Line};
%% do not crash if functions are exported, even though they
%% are not in the source.
%% parameterized modules add new/1 and instance/1 for example.
[] -> {Source, function_not_found}
end.

Yükleniyor…
İptal
Kaydet