erlang / otp

Erlang/OTP
http://erlang.org
Apache License 2.0
11.38k stars 2.95k forks source link

TypEr --annotate-inc-files not working #5653

Open elbrujohalcon opened 2 years ago

elbrujohalcon commented 2 years ago

Describe the bug typer crashes when trying to use the --annotate-inc-files option.

To Reproduce

  1. Create these two files:
    • inc.hrl
      included() -> included.
    • mod.erl
      
      -module(mod).

-export([exported/0]).

-include("inc.hrl").

exported() -> {not_exported(), included()}.

not_exported() -> not_exported.

2. Generate a PLT using dialyzer.
3. Run the following command…
```bash
typer --plt /path/to/your/plt --annotate-inc-files mod.erl

You'll see an error similar to…

      Processing file: "mod.erl"
{"init terminating in do_boot",{{badmatch,[{"inc.hrl",{3,included,0}}]},[{typer,write_typed_file,5,[{file,"typer.erl"},{line,495}]},{typer,write_typed_file,3,[{file,"typer.erl"},{line,489}]},{typer,'-write_and_collect_inc_info/1-fun-0-',3,[{file,"typer.erl"},{line,242}]},{lists,foldl,3,[{file,"lists.erl"},{line,1267}]},{typer,write_and_collect_inc_info,1,[{file,"typer.erl"},{line,246}]},{typer,show_or_annotate,1,[{file,"typer.erl"},{line,235}]},{typer,start,0,[{file,"typer.erl"},{line,92}]},{init,start_em,1,[]}]}}
init terminating in do_boot ({{badmatch,[{[_],{_}}]},[{typer,write_typed_file,5,[{_},{_}]},{typer,write_typed_file,3,[{_},{_}]},{typer,-write_and_collect_inc_info/1-fun-0-,3,[{_},{_}]},{lists,foldl,3,

Crash dump is being written to: erl_crash.dump...done

Expected behavior A file called typer_ann/inc.ann.hrl that looks like…

-spec included() -> 'included'.
included() -> included.

Affected versions I've experienced this issue in OTP 23.3.2 and OTP 24.0.2.

Additional context All other TypEr modes work fine…

/tmp/annotate$ typer mod.erl --show

%% File: "mod.erl"
%% ---------------
-spec exported() -> {'not_exported','included'}.
-spec not_exported() -> 'not_exported'.
-spec included() -> 'included'.
/tmp/annotate$ typer mod.erl --show-exported

%% File: "mod.erl"
%% ---------------
-spec exported() -> {'not_exported','included'}.
/tmp/annotate$ typer mod.erl --annotate
      Processing file: "mod.erl"
             Saved as: "./typer_ann/mod.ann.erl"
/tmp/annotate$ cat typer_ann/mod.ann.erl
-module(mod).

-export([exported/0]).

-include("inc.hrl").

-spec exported() -> {'not_exported','included'}.
exported() ->
    {not_exported(), included()}.

-spec not_exported() -> 'not_exported'.
not_exported() ->
    not_exported.
jhogberg commented 2 years ago

Thanks for your report! I don't think we have the time to fix this in the near future, but feel free to open a PR.