I’m having a hard time to fix the following dialyzer warnings:
lib/foo.ex:36:pattern_match
The pattern
{:ok, _pid, _ref, _opts}
can never match the type
{:error, _}
issued about a case/2
expression:
case init_daemon(opts) do
{:error, reason} ->
{:error, reason}
{:ok, pid, ref, opts} ->
{:ok, %{options: opts, deamons: [%{pid: pid, ref: ref, options: opts}]}}
end
Where init_daemon/1
does roughly this and issues a warning for itself because of an opaque type:
lib/foo.ex:161:call_with_opaque
The call :erlang.monitor('process',_pid@1::ssh:daemon_ref()) contains an opaque term in 2nd argument when terms of different types are expected in these positions}.
def init_daemon(_) do # simplified
daemon = :ssh.daemon(10022, …irrelevant set of options…)
case daemon do
{:ok, pid} ->
ref = Process.monitor(pid)
{:ok, pid, ref, %{}}
{:error, reason} ->
{:error, reason}
end
end
My current assumption is, that dialyzer
assumes, that in init_daemon/1
the :ok
branch will never used, as it were violating opaque types, and therefore considers the :ok
clause as superfluous in the first case/2
above. As if I temporarily remove the call to Process.monitor/1
and replace it with a static value, dialyzer
does not complain anymore.
But how could I fix that? I need a monitor for the daemon process, or at least some monitorlike behaviour.