dialyzer(3erl) | Erlang Module Definition | dialyzer(3erl) |
dialyzer - Dialyzer, a DIscrepancy AnaLYZer for ERlang programs.
Dialyzer is a static analysis tool that identifies software discrepancies, such as definite type errors, code that has become dead or unreachable because of programming error, and unnecessary tests, in single Erlang modules or entire (sets of) applications.
Dialyzer starts its analysis from either debug-compiled BEAM bytecode or from Erlang source code. The file and line number of a discrepancy is reported along with an indication of what the discrepancy is about. Dialyzer bases its analysis on the concept of success typings, which allows for sound warnings (no false positives).
Dialyzer has a command-line version for automated use. This section provides a brief description of the options. The same information can be obtained by writing the following in a shell:
dialyzer --help
For more details about the operation of Dialyzer, see section Using Dialyzer from the GUI in the User's Guide.
Exit status of the command-line version:
Usage:
dialyzer [--add_to_plt] [--apps applications] [--build_plt]
[--check_plt] [-Ddefine]* [-Dname]* [--dump_callgraph file]
[--error_location flag] [files_or_dirs] [--fullpath]
[--get_warnings] [--gui] [--help] [-I include_dir]*
[--no_check_plt] [--no_indentation] [-o outfile]
[--output_plt file] [-pa dir]* [--plt plt] [--plt_info]
[--plts plt*] [--quiet] [-r dirs] [--raw] [--remove_from_plt]
[--shell] [--src] [--statistics] [--verbose] [--version]
[-Wwarn]*
Options of the command-line version:
dialyzer --build_plt --apps erts kernel stdlib mnesia ...
to refer conveniently to library applications corresponding to the Erlang/OTP installation. However, this option is general and can also be used during analysis to refer to Erlang/OTP applications. File or directory names can also be included, as in:
dialyzer --apps inets ssl ./ebin ../other_lib/ebin/my_module.beam
dialyzer --build_plt --output_plt plt_1 files_to_include ... dialyzer --build_plt --output_plt plt_n files_to_include
They can then be used in either of the following ways:
dialyzer files_to_analyze --plts plt_1 ... plt_n
or
dialyzer --plts plt_1 ... plt_n -- files_to_analyze
Notice the -- delimiter in the second case.
Warning options:
The following options are also available, but their use is not recommended (they are mostly for Dialyzer developers and internal debugging):
The following option is not strictly needed as it specifies the default. It is primarily intended to be used with the -dialyzer attribute. For an example see section Requesting or Suppressing Warnings in Source Files.
Dialyzer can be used directly from Erlang. Both the GUI and the command-line versions are also available. The options are similar to the ones given from the command line, see section Using Dialyzer from the Command Line.
The (host operating system) environment variable ERL_COMPILER_OPTIONS can be used to give default Dialyzer options. Its value must be a valid Erlang term. If the value is a list, it is used as is. If it is not a list, it is put into a list.
The list is appended to any options given to run/1 or on the command line.
The list can be retrieved with compile:env_compiler_options/0.
Currently the only option used is the error_location option.
Attribute -dialyzer() can be used for turning off warnings in a module by specifying functions or warning options. For example, to turn off all warnings for the function f/0, include the following line:
-dialyzer({nowarn_function, f/0}).
To turn off warnings for improper lists, add the following line to the source file:
-dialyzer(no_improper_lists).
Attribute -dialyzer() is allowed after function declarations. Lists of warning options or functions are allowed:
-dialyzer([{nowarn_function, [f/0]}, no_improper_lists]).
Warning options can be restricted to functions:
-dialyzer({no_improper_lists, g/0}).
-dialyzer({[no_return, no_match], [g/0, h/0]}).
The warning option for underspecified functions, -Wunderspecs, can result in useful warnings, but often functions with specifications that are strictly more allowing than the success typing cannot easily be modified to be less allowing. To turn off the warning for underspecified function f/0, include the following line:
-dialyzer({no_underspecs, f/0}).
For help on the warning options, use dialyzer -Whelp. The options are also enumerated, see type warn_option().
Attribute -dialyzer() can also be used for turning on warnings. For example, if a module has been fixed regarding unmatched returns, adding the following line can help in assuring that no new unmatched return warnings are introduced:
-dialyzer(unmatched_returns).
dial_option() =
{files, [FileName :: file:filename()]} |
{files_rec, [DirName :: file:filename()]} |
{defines, [{Macro :: atom(), Value :: term()}]} |
{from, src_code | byte_code} |
{init_plt, FileName :: file:filename()} |
{plts, [FileName :: file:filename()]} |
{include_dirs, [DirName :: file:filename()]} |
{output_file, FileName :: file:filename()} |
{output_plt, FileName :: file:filename()} |
{check_plt, boolean()} |
{analysis_type,
succ_typings | plt_add | plt_build | plt_check | plt_remove} |
{warnings, [warn_option()]} |
{get_warnings, boolean()} |
{error_location, error_location()}
Option from defaults to byte_code. Options init_plt and plts change the default.
dial_warn_tag() =
warn_behaviour | warn_bin_construction | warn_callgraph |
warn_contract_not_equal | warn_contract_range |
warn_contract_subtype | warn_contract_supertype |
warn_contract_syntax | warn_contract_types |
warn_failing_call | warn_fun_app | warn_map_construction |
warn_matching | warn_non_proper_list | warn_not_called |
warn_opaque | warn_return_no_exit | warn_return_only_exit |
warn_undefined_callbacks | warn_unknown | warn_umatched_return
dial_warning() =
{Tag :: dial_warn_tag(),
Id :: file_location(),
Msg :: {atom(), [term()]}}
error_location() = column | line
If the value of this option is line, an integer Line is used as Location in messages. If the value is column, a pair {Line, Column} is used as Location. The default is column.
file_location() =
{File :: file:filename(), Location :: erl_anno:location()}
warn_option() =
error_handling | no_behaviours | no_contracts | no_fail_call |
no_fun_app | no_improper_lists | no_match | no_missing_calls |
no_opaque | no_return | no_undefined_callbacks |
no_underspecs | no_unused | underspecs | unknown |
unmatched_returns | overspecs | specdiffs | extra_return |
no_extra_return | missing_return | no_missing_return
See section Warning options for a description of the warning options.
format_warning(Warnings) -> string()
Types:
Get a string from warnings as returned by run/1.
format_warning(Warnings, Options) -> string()
Types:
format_option() =
{indent_opt, boolean()} |
{filename_opt, filename_opt()} |
{error_location, error_location()}
filename_opt() = basename | fullpath
Get a string from warnings as returned by run/1.
If indent_opt is set to true (default), line breaks are inserted in types, contracts, and Erlang code to improve readability.
If error_location is set to column (default), locations are formatted as Line:Column if the column number is available, otherwise locations are formatted as Line even if the column number is available.
gui() -> ok
gui(Options) -> ok
Types:
Dialyzer GUI version.
plt_info(Plt) -> {ok, Result} | {error, Reason}
Types:
Returns information about the specified PLT.
run(Options) -> Warnings
Types:
Dialyzer command-line version.
dialyzer 5.0.4 | Ericsson AB |