Reputation: 595
I am using the typer_core
module of Dialyzer to automatically infer typespecs. However, I am obtaining different behaviour based on whether the files specified are prepended with the .
character or not. The behaviour described below only affects files located in the directory where the typer command is run; files in child directories are processed as expected by Typer.
Consider the module test.erl
:
-module(test).
is_a_ok(a) -> ok.
The behaviour below is produced when evaluating the following expressions on the REPL:
% Prepending with the '.' character.
% Creates the file ./typer_ann/test.ann.erl, but is NOT annotated.
typer_core:run(#{mode => annotate, files => ["./test.erl"]}).
Processing file: "./test.erl"
Saved as: "./typer_ann/test.ann.erl"
% Does NOT annotate the file ./test.erl.
typer_core:run(#{mode => annotate_in_place, files => ["./test.erl"]}).
Processing file: "./test.erl"
Saved as: "./test.erl"
% Without the '.' character.
% Creates the file ./typer_ann/test.ann.erl, and is annotated.
typer_core:run(#{mode => annotate, files => ["test.erl"]}).
Processing file: "test.erl"
Saved as: "./typer_ann/test.ann.erl"
% Annotates the file ./test.erl.
typer_core:run(#{mode => annotate_in_place, files => ["test.erl"]}).
Processing file: "test.erl"
Saved as: "test.erl"
Using .
in conjunction with the files_r
key (equivalent to the -r
command line switch) processes directories recursively. I observed the same behaviour described above when attempting to annotate files with the files_r
key, specifying .
as the starting directory:
% Does NOT annotate any of the files in the current directory.
typer_core:run(#{mode => annotate_in_place, files_r => ["."]}).
Processing file: "./test.erl"
Saved as: "./test.erl"
This can be reproduced using Typer on the command line:
# Does NOT annotate the file ./test.erl.
$ typer --annotate-in-place ./test.erl
Processing file: "./test.erl"
Saved as: "./test.erl"
# Does NOT annotate any of the files in the current directory.
$ typer --annotate-in-place -r .
Processing file: "./test.erl"
Saved as: "./test.erl"
Note that, however, *.erl
files in child directories do get annotated in the first and last examples, i.e. using typer_core:run(#{mode => annotate_in_place, files_r => ["."]})
and typer --annotate-in-place -r .
The following examples also work:
# Annotates the file ./test.erl (no . in front of the file name).
$ typer --annotate-in-place test.erl
Processing file: "test.erl"
Saved as: "test.erl"
# Annotates the file test.erl (. in front of the directory, one directory up).
$ typer --annotate-in-place ./typer_test/test.erl
Processing file: "./typer_test/test.erl"
Saved as: "./typer_test/test.erl"
I might be missing something and would appreciate any suggestions regarding this behaviour. I am using OTP 25.0.4
.
Upvotes: 1
Views: 44