dialyzer(1)

✨ NAME ✨

dialyzer β€” bestie it is a DIscrepancy AnaLYZer for ERlang programs. πŸŽ€


πŸ’– DESCRIPTION πŸ’–

Dialyzer is a static analysis tool that sniffs out software discrepancies β€” like definite type errors, code that is unreachable because of programming errors, and unnecessary tests β€” whether you point it at a single Erlang module or your entire codebase. πŸ‘‘

It starts its analysis from either debug-compiled BEAM code or from Erlang source code. For every discrepancy it finds, it reports the file and line number plus a lil indicator of what kind of discrepancy it is. And the way it does this? It bases everything on the concept of success typings β€” which means it gives you sound warnings without false positives. no cap. πŸ’…

πŸ¦‹ Using Dialyzer from the Command Line πŸ¦‹

Okay so this section is the lil overview of what you can do from the command line. You can also just get the same info yourself by typing this into a shell:

dialyzer --help

Exit status of the command-line version, and yes you need to know these, they matter:

  • 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] [--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. fr fr, you can stack 'em.

Options of the command-line version:

  • --add_to_plt β€” Extends the PLT to also include the files you gave with -c and -r. Use --plt to say which PLT you're starting from, and --output_plt to say where the PLT gets put. Heads up: files that are already in the PLT will be reanalyzed if they depend on the new files. Also this only works for BEAM files, not source files. 🫢
  • --apps applications β€” By default, warnings get reported to all applications given by --apps. But if --warning_apps is used, then only those applications given to --warning_apps have warnings reported. Every application given by --apps but not --warning_apps still gets analysed so it can provide context to the analysis β€” it just doesn't get warnings reported for it. Example vibe: you may want to include libraries you depend on in the analysis with --apps so discrepancies in their usage can be found, but only include your own code with --warning_apps so that discrepancies are only reported in code that you own. periodt. πŸ‘‘
  • --warning_apps applications β€” This one is typically used when building or modifying a PLT, like:
dialyzer --build_plt --apps erts kernel stdlib mnesia ...

...which is a convenient way to refer 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 be included too, like:

dialyzer --apps inets ssl ./ebin ../other_lib/ebin/my_module.beam
  • --build_plt β€” The analysis starts from an empty PLT and creates a brand new one from the files specified with -c and -r. This option only works for BEAM files. If you wanna override the default PLT location, use --plt or --output_plt. 🧚
  • --check_plt β€” Checks the PLT for consistency and rebuilds it if it's not up-to-date. the way that it just fixes things for you πŸ’…
  • -Dname (or -Dname=value) β€” When analyzing from source, pass the define to Dialyzer. (**)
  • --dump_callgraph file β€” Dumps the call graph into the specified file, and the format is determined by the filename extension. Supported extensions are: raw, dot, and ps. If you use something else as the filename extension, the default .raw format is used. πŸ“
  • --error_location column | line β€” 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.
  • files_or_dirs (for backward compatibility also as -c files_or_dirs) β€” 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. ✨
  • --fullpath β€” Display the full path names of files for which warnings are emitted.
  • --get_warnings β€” Makes Dialyzer emit warnings even when manipulating the PLT. Warnings are only emitted for files that are analyzed.
  • --help (or -h) β€” Print a help message and exit. classic. πŸ™ˆ
  • -I include_dir β€” When analyzing from source, pass the include_dir to Dialyzer. (**)
  • --input_list_file file β€” Analyze the file names that are listed in the specified file (one file name per line).
  • --no_check_plt β€” Skips the PLT check when running Dialyzer. Super useful when you're working with installed PLTs that never change. πŸ”₯
  • --incremental β€” The analysis starts from an existing incremental PLT, or builds one from scratch if one doesn't exist, and runs the minimal amount of additional analysis needed to report all issues in the given set of apps. Lowkey important: incremental PLT files are not compatible with "classic" PLT files, and vice versa. The initial incremental PLT will be updated unless you give an alternative output incremental PLT.
  • --no_indentation β€” Do not insert line breaks in types, contracts, and Erlang Code when formatting warnings.
  • --no_spec β€” Ignore function specs. This is useful for debugging when you suspect that some specs are incorrect. πŸ‘€
  • -o outfile (or --output outfile) β€” When using Dialyzer from the command line, send the analysis results to the specified outfile rather than to stdout.
  • --metrics_file file β€” Write metrics about Dialyzer's incrementality to a file β€” for example, total number of modules considered, how many modules were changed since the PLT was last updated, how many modules needed to be analyzed. This can be useful for tracking and debugging Dialyzer's incrementality. πŸ“Š
  • --output_plt file β€” Store the PLT at the specified file after building it.
  • -pa dir β€” Include dir in the path for Erlang. This is useful when analyzing files that have -include_lib() directives. 🫢
  • --plt plt β€” Use the specified PLT as the initial PLT. If the PLT was built during setup, the files are checked for consistency.
  • --plt_info β€” Makes Dialyzer print information about the PLT and then quit. The PLT can be specified with --plt(s).
  • --plts plt* β€” 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. don't forget it bestie, it's giving load-bearing πŸ’€

  • --quiet (or -q) β€” Makes Dialyzer a bit more quiet. 🀫
  • -r dirs β€” 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.
  • --raw β€” 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). 🌈
  • --remove_from_plt β€” 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. 😭
  • --src β€” Overrides the default, which is to analyze BEAM files, and analyzes starting from Erlang source code instead.
  • --statistics β€” Print information about the progress of execution (analysis phases, time spent in each, and size of the relative input). ⏱️
  • --verbose β€” Makes Dialyzer a bit more verbose. πŸ—£οΈ
  • --version (or -v) β€” Print the Dialyzer version and some more information and exit.
  • -Wwarn β€” 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: ** the syntax of defines and includes is the same as that used by erlc.

πŸ‘‘ Warning options πŸ‘‘

  • -Werror_handling (***) β€” Include warnings for functions that only return by an exception.
  • -Wextra_return (***) β€” Warn about functions whose specification includes types that the function cannot return.
  • -Wmissing_return (***) β€” Warn about functions that return values that are not part of the specification.
  • -Wno_behaviours β€” Suppress warnings about behavior callbacks that drift from the published recommended interfaces. πŸ¦‹
  • -Wno_contracts β€” Suppress warnings about invalid contracts.
  • -Wno_fail_call β€” Suppress warnings for failing calls.
  • -Wno_fun_app β€” Suppress warnings for fun applications that will fail.
  • -Wno_improper_lists β€” Suppress warnings for construction of improper lists.
  • -Wno_match β€” Suppress warnings for patterns that are unused or cannot match.
  • -Wno_missing_calls β€” Suppress warnings about calls to missing functions.
  • -Wno_opaque β€” Suppress warnings for violations of opacity of data types.
  • -Wno_return β€” Suppress warnings for functions that will never return a value.
  • -Wno_undefined_callbacks β€” Suppress warnings about behaviors that have no -callback attributes for their callbacks.
  • -Wno_unused β€” Suppress warnings for unused functions.
  • -Wno_unknown β€” Suppress warnings about unknown functions and types. The default is to warn about unknown functions and types when setting the exit status. When using Dialyzer from Erlang, warnings about unknown functions and types are returned.
  • -Wunderspecs (***) β€” Warn about underspecified functions (the specification is strictly more allowing than the success typing).

✨ okay that's part 1 bestie β€” more incoming, don't go anywhere πŸ’–

  • -Wunmatched_returns (***) β€” ok so this one makes Dialyzer warn when a function call just… ignores a structured return value, or doesn't match against one of many possible return values. messy behavior, we don't love it. That said β€” no warnings get reported if those possible return values are a union of atoms or a union of numbers. Bestie, it just doesn't care in that case.

The next ones exist, but the manual straight up says their use is not recommended β€” they're mostly for Dialyzer developers and internal debugging, iykyk. πŸ™ˆ

  • -Woverspecs (***) β€” warn about overspecified functions, meaning the specification is strictly less allowing than the success typing.
  • -Wspecdiffs (***) β€” warn when the specification is different than the success typing.
NOTE: the * means these options turn warnings **on rather than turning them off. Very much the opposite energy of the no_ ones. πŸ’…

The following options are not strictly needed because they just specify the default. They're primarily meant to be used with the -dialyzer attribute β€” for an example, peek at the section Requesting or Suppressing Warnings in Source Files. 🫢

  • -Wno_underspecs β€” suppress warnings about underspecified functions (where the specification is strictly more allowing than the success typing).
  • -Wno_extra_return β€” suppress warnings about functions whose specification includes types that the function cannot return.
  • -Wno_missing_return β€” suppress warnings about functions that return values that are not part of the specification.

🌈 Using Dialyzer from Erlang 🌈

You can use Dialyzer directly from Erlang, no shell needed. The options are similar to the ones you'd give from the command line. See the section Using Dialyzer from the Command Line. ✨


πŸŽ€ Default Dialyzer Options πŸŽ€

The (host operating system) environment variable ERL_COMPILER_OPTIONS can be used to give Dialyzer its default 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. no cap.

That 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. literally just the one.

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's commonly used to avoid repeating options which would otherwise need to be given explicitly to Dialyzer on every invocation. time-saver behavior tbh.

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 πŸ¦‹

The 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. bestie said "check the type, it's all there." ✨

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. important, don't forget it.

dial_warn_tag() ::
          warn_behaviour | warn_bin_construction | warn_callgraph |
          warn_contract_extra_return | warn_contract_missing_return |
          warn_contract_not_equal | warn_contract_opaque |
          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_overlapping_contract |
          warn_return_no_exit | warn_return_only_exit |
          warn_undefined_callbacks | warn_unknown |
warn_umatched_return.
heads up: that last one really is spelled warn_umatched_return in the source. not a typo on my part, I promise, I am not touching it. πŸ’€
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()}.
filename_opt() :: basename | fullpath.
format_option() ::
          {indent_opt, boolean()} |
          {filename_opt, filename_opt()} |
          {error_location, error_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_unknown | no_unused | underspecs |
          unknown | unmatched_returns | overspecs | specdiffs |
          overlapping_contract | extra_return | no_extra_return |
          missing_return | no_missing_return | opaque_union.

See the 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. simple as that.
  • format_warning(Warnings, Options) -> string() β€” when Warnings :: dial_warning(), Options :: filename_opt() | [format_option()]. 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. readable era. 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. yes, even then.
  • plt_info(Plt) -> {ok, ClassicResult | IncrementalResult} | {error, Reason} β€” when
Plt :: file:filename(),
ClassicResult :: [{files, [file:filename()]}],
IncrementalResult ::
    {incremental, [{modules, [module()]}]},
Reason :: not_valid | no_such_file | read_error.

Returns information about the specified PLT. receipts for your PLT.

  • run(Options) -> Warnings β€” when Options :: [dial_option()], Warnings :: [dial_warning()]. Run Dialyzer and return warnings. πŸ”₯

and that's the whole page, bestie β€” you made it to the end, main character energy fr fr. Ericsson AB made this, it's dialyzer 6.0.2 from the dialyzer(1) manual page β€” go forth and let the warnings find you. πŸ’…βœ¨πŸŽ€

πŸ“¦ where this page comes from