Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if function is exported rather than relying on OTP_RELEASE #1518

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 26 additions & 10 deletions apps/els_lsp/src/els_typer.erl
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,6 @@

-include("els_lsp.hrl").

-if(?OTP_RELEASE >= 26).
-define(DEFAULT_PLT_FILE, dialyzer_iplt:get_default_iplt_filename()).
-define(PLT_FROM_FILE(PltFile), dialyzer_iplt:from_file(PltFile)).
-else.
-define(DEFAULT_PLT_FILE, dialyzer_plt:get_default_plt()).
-define(PLT_FROM_FILE(PltFile), dialyzer_plt:from_file(PltFile)).
-endif.

-type files() :: [file:filename()].
-type callgraph() :: dialyzer_callgraph:callgraph().
-type codeserver() :: dialyzer_codeserver:codeserver().
Expand Down Expand Up @@ -435,11 +427,11 @@ get_dialyzer_plt() ->
PltFile =
case els_config:get(plt_path) of
undefined ->
?DEFAULT_PLT_FILE;
default_plt_file();
PltPath ->
PltPath
end,
?PLT_FROM_FILE(PltFile).
plt_from_file(PltFile).

%% Exported Types

Expand Down Expand Up @@ -503,3 +495,27 @@ map__lookup(Key, Map) ->
-spec map__from_list([{fa(), term()}]) -> map_dict().
map__from_list(List) ->
dict:from_list(List).

-dialyzer({nowarn_function, default_plt_file/0}).

-spec default_plt_file() -> file:filename().
default_plt_file() ->
%% OTP 26+ uses dialyzer_iplt
case erlang:function_exported(dialyzer_iplt, get_default_iplt_filename, 0) of
true ->
dialyzer_iplt:get_default_iplt_filename();
false ->
dialyzer_plt:get_default_plt()
end.

-dialyzer({nowarn_function, plt_from_file/1}).

-spec plt_from_file(file:filename()) -> dialyzer_plt:plt().
plt_from_file(PltFile) ->
%% OTP 26+ uses dialyzer_iplt
case erlang:function_exported(dialyzer_iplt, from_file, 1) of
true ->
dialyzer_iplt:from_file(PltFile);
false ->
dialyzer_plt:from_file(PltFile)
end.
4 changes: 4 additions & 0 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@
{http_uri, decode, 1},
{shell_docs, render, 4},
{uri_string, percent_decode, 1},
{dialyzer_plt, get_default_plt, 0},
{dialyzer_plt, from_file, 1},
{dialyzer_iplt, get_default_iplt_filename, 0},
{dialyzer_iplt, from_file, 1},
wrangler_handler,
api_wrangler,
wls_code_lens,
Expand Down
Loading