Skip to content

Instantly share code, notes, and snippets.

@jesperes
Last active March 3, 2022 07:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jesperes/4265139e0e8f597ea5d9fd368b6bf8af to your computer and use it in GitHub Desktop.
Save jesperes/4265139e0e8f597ea5d9fd368b6bf8af to your computer and use it in GitHub Desktop.
Dialyzer bug in OTP 24.x
-module(epgsql).
-export_type([connect_opts/0]).
-type connect_opts() :: foo:bar(). %% unknown type here
-module(epgsql_cmd_connect).
-export([open_socket/1]).
%% ... no code at line 3 ...
-spec open_socket(epgsql:connect_opts()) -> ok.
open_socket(_ConnectOpts) ->
ok.
$ ./run.sh
+ erlc +debug_info epgsql_cmd_connect.erl epgsql.erl
+ dialyzer epgsql.beam epgsql_cmd_connect.beam --plt /home/jespereskilson/dev/kred/build/otp.plt --no_check_plt
Proceeding with analysis...
Unknown types:
foo:bar/0 (epgsql.erl:3:25)
foo:bar/0 (epgsql_cmd_connect.erl:3:25)
done in 0m0.57s
done (passed successfully)
#!/bin/bash
set -x
erlc +debug_info *.erl
dialyzer *.beam --plt ~/dev/kred/build/otp.plt --no_check_plt
@jesperes
Copy link
Author

jesperes commented Mar 3, 2022

Dialyzer reports two errors, but the second one is wrong.

  foo:bar/0 (src/epgsql.erl:3:25)
  foo:bar/0 (src/epgsql_cmd_connect.erl:3:25)

The first one is correct, as the type foo:bar() does not exist.

  1. The first bug is that second errors is bogus, because the spec -spec open_socket(epgsql:connect_opts()) -> ok. does not refer to an unknown type.
  2. The second bug is that the the line and column info for the second bug is definitely wrong; it refers to the location of the first error, but has the filename of the second error.

@jesperes
Copy link
Author

jesperes commented Mar 3, 2022

OTP versions prior to 24 are not affected. All OTP 24.x-25.x versions are affected.

@jesperes
Copy link
Author

jesperes commented Mar 3, 2022

To reproduce this error, use "download zip", unpack it locally, and run the run.sh script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment