Scroll to navigation

dialyzer(1) User Commands dialyzer(1)

NAME

dialyzer - Dialyzer, a DIscrepancy AnaLYZer for ERlang programs.

DESCRIPTION

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).

USING DIALYZER FROM THE COMMAND LINE

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:

0:
No problems were found during the analysis and no warnings were emitted.
1:
Problems were found during the analysis.
2:
No problems were found during the analysis, but warnings were emitted.

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]*
Note:
* denotes that multiple occurrences of the option are possible.

Options of the command-line version:

The PLT is extended to also include the files specified with -c and -r. Use --plt to specify which PLT to start from, and --output_plt to specify where to put the PLT. Notice that the analysis possibly can include files from the PLT if they depend on the new files. This option only works for BEAM files.
This option is typically used when building or modifying a PLT as in:

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
The analysis starts from an empty PLT and creates a new one from the files specified with -c and -r. This option only works for BEAM files. To override the default PLT location, use --plt or --output_plt.
Check the PLT for consistency and rebuild it if it is not up-to-date.
When analyzing from source, pass the define to Dialyzer. (**)
Dump the call graph into the specified file whose format is determined by the filename extension. Supported extensions are: raw, dot, and ps. If something else is used as filename extension, default format .raw is used.
Use a pair {Line, Column} or an integer Line to pinpoint the location of warnings. The default is to use a pair {Line, Column}. When formatted, the line and the column are separated by a colon.
Use Dialyzer from the command line to detect defects in the specified files or directories containing .erl or .beam files, depending on the type of the analysis.
Display the full path names of files for which warnings are emitted.
Make Dialyzer emit warnings even when manipulating the PLT. Warnings are only emitted for files that are analyzed.
Use the GUI.
Print this message and exit.
When analyzing from source, pass the include_dir to Dialyzer. (**)
Skip the PLT check when running Dialyzer. This is useful when working with installed PLTs that never change.
Do not insert line breaks in types, contracts, and Erlang Code when formatting warnings.
When using Dialyzer from the command line, send the analysis results to the specified outfile rather than to stdout.
Store the PLT at the specified file after building it.
Include dir in the path for Erlang. This is useful when analyzing files that have -include_lib() directives.
Use the specified PLT as the initial PLT. If the PLT was built during setup, the files are checked for consistency.
Make Dialyzer print information about the PLT and then quit. The PLT can be specified with --plt(s).
Merge the specified PLTs to create the initial PLT. This requires that the PLTs are disjoint (that is, do not have any module appearing in more than one PLT). The PLTs are created in the usual way:

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.

Make Dialyzer a bit more quiet.
Same as files_or_dirs, but the specified directories are searched recursively for subdirectories containing .erl or .beam files in them, depending on the type of analysis.
When using Dialyzer from the command line, output the raw analysis results (Erlang terms) instead of the formatted result. The raw format is easier to post-process (for example, to filter warnings or to output HTML pages).
The information from the files specified with -c and -r is removed from the PLT. Notice that this can cause a reanalysis of the remaining dependent files.
Do not disable the Erlang shell while running the GUI.
Override the default, which is to analyze BEAM files, and analyze starting from Erlang source code instead.
Print information about the progress of execution (analysis phases, time spent in each, and size of the relative input).
Make Dialyzer a bit more verbose.
Print the Dialyzer version and some more information and exit.
A family of options that selectively turn on/off warnings. (For help on the names of warnings, use dialyzer -Whelp.) Notice that the options can also be specified in the file with a -dialyzer() attribute. For details, see section Requesting or Suppressing Warnings in Source Files.
Note:
** options -D and -I work both from the command line and in the Dialyzer GUI; the syntax of defines and includes is the same as that used by erlc(1).

Warning options:

Include warnings for functions that only return by an exception.
Suppress warnings about behavior callbacks that drift from the published recommended interfaces.
Suppress warnings about invalid contracts.
Suppress warnings for failing calls.
Suppress warnings for fun applications that will fail.
Suppress warnings for construction of improper lists.
Suppress warnings for patterns that are unused or cannot match.
Suppress warnings about calls to missing functions.
Suppress warnings for violations of opacity of data types.
Suppress warnings for functions that will never return a value.
Suppress warnings about behaviors that have no -callback attributes for their callbacks.
Suppress warnings for unused functions.
Include warnings for possible race conditions. Notice that the analysis that finds data races performs intra-procedural data flow analysis and can sometimes explode in time. Enable it at your own risk.
Warn about underspecified functions (the specification is strictly more allowing than the success typing).
Let warnings about unknown functions and types affect the exit status of the command-line version. The default is to ignore warnings about unknown functions and types when setting the exit status. When using Dialyzer from Erlang, warnings about unknown functions and types are returned; the default is not to return these warnings.
Include warnings for function calls that ignore a structured return value or do not match against one of many possible return values. However, no warnings are included if the possible return values are a union of atoms or a union of numbers.

The following options are also available, but their use is not recommended (they are mostly for Dialyzer developers and internal debugging):

Warn about overspecified functions (the specification is strictly less allowing than the success typing).
Warn when the specification is different than the success typing.
Note:
*** denotes options that turn on warnings rather than turning them off.

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.

Suppress warnings about underspecified functions (the specification is strictly more allowing than the success typing).

USING DIALYZER FROM ERLANG

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.

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.

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().

Note:
Warning option -Wrace_conditions has no effect when set in source files.

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()} |
{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_race_condition | 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 | race_conditions | underspecs |
unknown | unmatched_returns | overspecs | specdiffs

See section Warning options for a description of the warning options.

EXPORTS


format_warning(Warnings) -> string()


Types:

Warnings = dial_warning()

Get a string from warnings as returned by run/1.


format_warning(Warnings, Options) -> string()


Types:

Warnings = dial_warning()
Options = filename_opt() | [format_option()]
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:

Options = [dial_option()]

Dialyzer GUI version.


plt_info(Plt) -> {ok, Result} | {error, Reason}


Types:

Plt = file:filename()
Result = [{files, [file:filename()]}]
Reason = not_valid | no_such_file | read_error

Returns information about the specified PLT.


run(Options) -> Warnings


Types:

Options = [dial_option()]
Warnings = [dial_warning()]

Dialyzer command-line version.

dialyzer 4.4.4 Ericsson AB