25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-20 16:15:59 +01:00

Improve detection of types in odbc

This should fix issue with dialyzer on erlang 26.2.3+
This commit is contained in:
Paweł Chmielowski 2024-03-18 14:54:32 +01:00
parent 8f20dd8425
commit 537aac24f7
4 changed files with 43 additions and 7 deletions

17
mix.exs
View File

@ -80,6 +80,20 @@ defmodule Ejabberd.MixProject do
end end
end end
defp if_type_exported(module, typeDef, okResult) do
try do
{:ok, concrete} = :dialyzer_utils.get_core_from_beam(:code.which(module))
{:ok, types} = :dialyzer_utils.get_record_and_type_info(concrete)
if Maps.has_key(types, typeDef) do
okResult
else
[]
end
rescue
_ -> []
end
end
defp erlc_options do defp erlc_options do
# Use our own includes + includes from all dependencies # Use our own includes + includes from all dependencies
includes = ["include", deps_include()] includes = ["include", deps_include()]
@ -97,7 +111,8 @@ defmodule Ejabberd.MixProject do
if_version_below(~c"24", [{:d, :COMPILER_REPORTS_ONLY_LINES}]) ++ if_version_below(~c"24", [{:d, :COMPILER_REPORTS_ONLY_LINES}]) ++
if_version_below(~c"24", [{:d, :SYSTOOLS_APP_DEF_WITHOUT_OPTIONAL}]) ++ if_version_below(~c"24", [{:d, :SYSTOOLS_APP_DEF_WITHOUT_OPTIONAL}]) ++
if_version_below(~c"24", [{:d, :OTP_BELOW_24}]) ++ if_version_below(~c"24", [{:d, :OTP_BELOW_24}]) ++
if_version_below(~c"25", [{:d, :OTP_BELOW_25}]) if_version_below(~c"25", [{:d, :OTP_BELOW_25}]) ++
if_type_exported(:odbc, {:opaque, :connection_reference, 0}, [{:d, :ODBC_HAS_TYPES}])
defines = for {:d, value} <- result, do: {:d, value} defines = for {:d, value} <- result, do: {:d, value}
result ++ [{:d, :ALL_DEFS, defines}] result ++ [{:d, :ALL_DEFS, defines}]
end end

View File

@ -152,6 +152,7 @@
{if_var_true, roster_gateway_workaround, {d, 'ROSTER_GATEWAY_WORKAROUND'}}, {if_var_true, roster_gateway_workaround, {d, 'ROSTER_GATEWAY_WORKAROUND'}},
{if_var_true, sip, {d, 'SIP'}}, {if_var_true, sip, {d, 'SIP'}},
{if_var_true, stun, {d, 'STUN'}}, {if_var_true, stun, {d, 'STUN'}},
{if_type_exported, {odbc, {opaque, connection_reference, 0}}, {d, 'ODBC_HAS_TYPES'}},
{src_dirs, [src, {src_dirs, [src,
{if_rebar3, sql}, {if_rebar3, sql},
{if_var_true, tools, tools}]}]}. {if_var_true, tools, tools}]}]}.

View File

@ -151,6 +151,30 @@ ProcessVars = fun F([], Acc) ->
false -> false ->
F(Tail, Acc) F(Tail, Acc)
end; end;
F([{Type, {Mod, TypeDef}, Value} | Tail], Acc) when
Type == if_type_exported orelse
Type == if_type_not_exported ->
try
{ok, Concrete} = dialyzer_utils:get_core_from_beam(code:which(Mod)),
{ok, Types} = dialyzer_utils:get_record_and_type_info(Concrete),
maps:get(TypeDef, Types, undefined)
of
undefined when Type == if_type_not_exported ->
F(Tail, ProcessSingleVar(F, Value, Acc));
undefined ->
F(Tail, Acc);
_ when Type == if_type_exported ->
F(Tail, ProcessSingleVar(F, Value, Acc));
_ ->
F(Tail, Acc)
catch _:_ ->
if
Type == if_type_not_exported ->
F(Tail, ProcessSingleVar(F, Value, Acc));
true ->
F(Tail, Acc)
end
end;
F([Other1 | Tail1], Acc) -> F([Other1 | Tail1], Acc) ->
F(Tail1, [F(Other1, []) | Acc]); F(Tail1, [F(Other1, []) | Acc]);
F(Val, Acc) when is_tuple(Val) -> F(Val, Acc) when is_tuple(Val) ->

View File

@ -67,12 +67,8 @@
-export([connecting/2, connecting/3, -export([connecting/2, connecting/3,
session_established/2, session_established/3]). session_established/2, session_established/3]).
-ifdef(OTP_RELEASE). -ifdef(ODBC_HAS_TYPES).
-if(?OTP_RELEASE >= 27).
-type(odbc_connection_reference() :: odbc:connection_reference()). -type(odbc_connection_reference() :: odbc:connection_reference()).
-else.
-type(odbc_connection_reference() :: pid()).
-endif.
-else. -else.
-type(odbc_connection_reference() :: pid()). -type(odbc_connection_reference() :: pid()).
-endif. -endif.