table of contents
- trixie 1:27.3.4.1+dfsg-1+deb13u1
- testing 1:27.3.4.11+dfsg-1
- unstable 1:27.3.4.11+dfsg-3
- experimental 1:29.0~rc3+dfsg-2
| dialyzer(1) | Erlang Module Definition | dialyzer(1) |
NAME¶
dialyzer - Dialyzer is a DI*screpancy A*na*LYZ*er for **ER*lang programs.
DESCRIPTION¶
Dialyzer is a static analysis tool that identifies software discrepancies, such as definite type errors, code that is unreachable because of programming errors, and unnecessary tests in single Erlang modules or an entire codebase.
Dialyzer starts its analysis from either debug-compiled BEAM code or from Erlang source code. The file and line number of a discrepancy is reported along with an indication of the nature of the discrepancy. Dialyzer bases its analysis on the concept of success typings, ensuring sound warnings without false positives.
Using Dialyzer from the Command Line¶
This section provides a brief description of the options available when running Dialyzer from the command line. The same information can be obtained by writing the following in a shell:
-
dialyzer --help
Exit status of the command-line version:
0
1
2
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] [--help] [-I include_dir]*
[--incremental] [--metrics_file] [--no_check_plt] [--no_indentation]
[--no_spec] [-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] [--warning_apps applications] [-Wwarn]*
NOTE: * denotes that multiple occurrences of the option are possible.
Options of the command-line version:
--add_to_plt
--apps applications
--warning_apps applications
-
dialyzer --build_plt --apps erts kernel stdlib mnesia ...
to refer conveniently to library applications corresponding to the Erlang/OTP installation. This option 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
--build_plt
--check_plt
-Dname (or -Dname=value)
--dump_callgraph file
--error_location column | line
files_or_dirs (for backward compatibility also as -c files_or_dirs)
--fullpath
--get_warnings
--help (or -h)
-I include_dir
--input_list_file file
--no_check_plt
--incremental
--no_indentation
--no_spec
-o outfile (or --output outfile)
--metrics_file file
--output_plt file
-pa dir
--plt plt
--plt_info
--plts plt*
-
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.
--quiet (or -q)
-r dirs
--raw
--remove_from_plt
--src
--statistics
--verbose
--version (or -v)
-Wwarn
NOTE: ** the syntax of defines and includes is the same as that used by erlc.
Warning options:
-Werror_handling (***)
-Wextra_return (***)
-Wmissing_return (***)
-Wno_behaviours
-Wno_contracts
-Wno_fail_call
-Wno_fun_app
-Wno_improper_lists
-Wno_match
-Wno_missing_calls
-Wno_opaque
-Wno_return
-Wno_undefined_callbacks
-Wno_unused
-Wno_unknown
-Wunderspecs (***)
-Wunmatched_returns (***)
The following options are also available, but their use is not recommended (they are mostly for Dialyzer developers and internal debugging):
-Woverspecs (***)
-Wspecdiffs (***)
NOTE: *** denotes options that turn on warnings rather than turning them off.
The following options are not strictly needed as they specify the default. They are primarily intended to be used with the -dialyzer attribute. For an example see section Requesting or Suppressing Warnings in Source Files.
-Wno_underspecs
-Wno_extra_return
-Wno_missing_return
Using Dialyzer from Erlang¶
Dialyzer can be used directly from Erlang. The options are similar to the ones given from the command line. See section Using Dialyzer from the Command Line.
Default Dialyzer Options¶
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.
Dialyzer configuration file:
Dialyzer's configuration file may also be used to augment the default options and those given directly to the Dialyzer command. It is commonly used to avoid repeating options which would otherwise need to be given explicitly to Dialyzer on every invocation.
The location of the configuration file can be set via the DIALYZER_CONFIG environment variable, and defaults to within the user_config from filename:basedir/3.
An example configuration file's contents might be:
-
{incremental,
{default_apps,[stdlib,kernel,erts]},
{default_warning_apps,[stdlib]}
}.
{warnings, [no_improper_lists]}.
{add_pathsa,["/users/samwise/potatoes/ebin"]}.
{add_pathsz,["/users/smeagol/fish/ebin"]}.
Requesting or Suppressing Warnings in Source Files¶
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/0.
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).
DATA TYPES¶
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()} | {metrics_file, FileName :: file:filename()} | {module_lookup_file, FileName :: file:filename()} | {output_plt, FileName :: file:filename()} | {check_plt, boolean()} | {analysis_type, succ_typings | plt_add | plt_build | plt_check | plt_remove | incremental} | {warnings, [warn_option()]} | {get_warnings, boolean()} | {use_spec, boolean()} | {filename_opt, filename_opt()} | {callgraph_file, file:filename()} | {mod_deps_file, file:filename()} | {warning_files_rec, [DirName :: file:filename()]} | {error_location, error_location()}.
Option from defaults to byte_code. Options init_plt and plts change the default.
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.
See section Warning options for a description of the warning options.
FUNCTIONS¶
format_warning(Warnings) -> string() when Warnings :: dial_warning().
Get a string from warnings as returned by run/1.
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.
Returns information about the specified PLT.
Run Dialyzer and return warnings.
| dialyzer 6.0 | Ericsson AB |