Skip to content

Commit 537aac2

Browse files
committed
Improve detection of types in odbc
This should fix issue with dialyzer on erlang 26.2.3+
1 parent 8f20dd8 commit 537aac2

File tree

4 files changed

+43
-7
lines changed

4 files changed

+43
-7
lines changed

mix.exs

+16-1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,20 @@ defmodule Ejabberd.MixProject do
8080
end
8181
end
8282

83+
defp if_type_exported(module, typeDef, okResult) do
84+
try do
85+
{:ok, concrete} = :dialyzer_utils.get_core_from_beam(:code.which(module))
86+
{:ok, types} = :dialyzer_utils.get_record_and_type_info(concrete)
87+
if Maps.has_key(types, typeDef) do
88+
okResult
89+
else
90+
[]
91+
end
92+
rescue
93+
_ -> []
94+
end
95+
end
96+
8397
defp erlc_options do
8498
# Use our own includes + includes from all dependencies
8599
includes = ["include", deps_include()]
@@ -97,7 +111,8 @@ defmodule Ejabberd.MixProject do
97111
if_version_below(~c"24", [{:d, :COMPILER_REPORTS_ONLY_LINES}]) ++
98112
if_version_below(~c"24", [{:d, :SYSTOOLS_APP_DEF_WITHOUT_OPTIONAL}]) ++
99113
if_version_below(~c"24", [{:d, :OTP_BELOW_24}]) ++
100-
if_version_below(~c"25", [{:d, :OTP_BELOW_25}])
114+
if_version_below(~c"25", [{:d, :OTP_BELOW_25}]) ++
115+
if_type_exported(:odbc, {:opaque, :connection_reference, 0}, [{:d, :ODBC_HAS_TYPES}])
101116
defines = for {:d, value} <- result, do: {:d, value}
102117
result ++ [{:d, :ALL_DEFS, defines}]
103118
end

rebar.config

+1
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@
152152
{if_var_true, roster_gateway_workaround, {d, 'ROSTER_GATEWAY_WORKAROUND'}},
153153
{if_var_true, sip, {d, 'SIP'}},
154154
{if_var_true, stun, {d, 'STUN'}},
155+
{if_type_exported, {odbc, {opaque, connection_reference, 0}}, {d, 'ODBC_HAS_TYPES'}},
155156
{src_dirs, [src,
156157
{if_rebar3, sql},
157158
{if_var_true, tools, tools}]}]}.

rebar.config.script

+24
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,30 @@ ProcessVars = fun F([], Acc) ->
151151
false ->
152152
F(Tail, Acc)
153153
end;
154+
F([{Type, {Mod, TypeDef}, Value} | Tail], Acc) when
155+
Type == if_type_exported orelse
156+
Type == if_type_not_exported ->
157+
try
158+
{ok, Concrete} = dialyzer_utils:get_core_from_beam(code:which(Mod)),
159+
{ok, Types} = dialyzer_utils:get_record_and_type_info(Concrete),
160+
maps:get(TypeDef, Types, undefined)
161+
of
162+
undefined when Type == if_type_not_exported ->
163+
F(Tail, ProcessSingleVar(F, Value, Acc));
164+
undefined ->
165+
F(Tail, Acc);
166+
_ when Type == if_type_exported ->
167+
F(Tail, ProcessSingleVar(F, Value, Acc));
168+
_ ->
169+
F(Tail, Acc)
170+
catch _:_ ->
171+
if
172+
Type == if_type_not_exported ->
173+
F(Tail, ProcessSingleVar(F, Value, Acc));
174+
true ->
175+
F(Tail, Acc)
176+
end
177+
end;
154178
F([Other1 | Tail1], Acc) ->
155179
F(Tail1, [F(Other1, []) | Acc]);
156180
F(Val, Acc) when is_tuple(Val) ->

src/ejabberd_sql.erl

+2-6
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,8 @@
6767
-export([connecting/2, connecting/3,
6868
session_established/2, session_established/3]).
6969

70-
-ifdef(OTP_RELEASE).
71-
-if(?OTP_RELEASE >= 27).
72-
-type(odbc_connection_reference() :: odbc:connection_reference()).
73-
-else.
74-
-type(odbc_connection_reference() :: pid()).
75-
-endif.
70+
-ifdef(ODBC_HAS_TYPES).
71+
-type(odbc_connection_reference() :: odbc:connection_reference()).
7672
-else.
7773
-type(odbc_connection_reference() :: pid()).
7874
-endif.

0 commit comments

Comments
 (0)