[Dialyzer]: Process.demonitor always returns true?

Hello,

I am having trouble understanding Dialyzer here:

Code that works fine:

  def foo(_ref, pid) do
    a = :random.uniform(1) == 1
    b = Process.alive?(pid)
    a and b
  end

Code that pisses Dialyzer off:

  def foo(ref, pid) do
    a = Process.demonitor(ref)
    b = Process.alive?(pid)
    a and b
  end
The pattern can never match the type.

Pattern:
false

Type:
true

I think I’ve distilled the problem down to the fact that dialyzer thinks Process.demonitor(ref) call is always true, and passing that value to and is as redundant as saying true && bar().

However, why is Process.demonitor(ref) considered to always return true? The spec clearly states boolean() type.

1 Like
iex(17)> h :erlang.demonitor

                              :erlang.demonitor/1

  @spec demonitor(monitorRef) :: true when monitorRef: reference()

Module was compiled without docs. Showing only specs.

I guess the 1 arity is always returning true after all.

1 Like