Dialyzer: suppress warning on a specific function

In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to turn off a specific warning for a function:

-dialyzer({no_return, g/0}).

If I’m understanding correctly, this should turn off the ‘function has no local return’ warning.

Is there a way to express this in Elixir? The following is giving me an ArithmeticError:

@dialyzer {:no_return, :g/0}
1 Like

Maybe @dialyzer {:no_return, :"g/0"}, however, -dialyzer, an attribute in erlang may be not the same as @dialyzer, a module attribute in elixir.

If I recall correctly, its @dialyzer {:no_return, {:g, 0}}.

3 Likes

Right!

defmodule Myapp.Repo do
  use Ecto.Repo, otp_app: :myapp
  @dialyzer {:nowarn_function, rollback: 1}
end

from https://github.com/jeremyjh/dialyxir/wiki/Phoenix-Dialyxir-Quickstart

So -dialyzer({no_return, g/0}). would probably become

@dialyzer {:no_return, g: 0}
7 Likes

Thank you both! That works perfectly.

I think this way is better, some function that calling the g/0 function also will be disabled

  @dialyzer {:noreturn_function, g: 0}

For posterity: you can also disable warnings for functions for third-party deps/modules:

@dialyzer {:nowarn_function, &MyXQL.rollback/2}
# somewhere later...
    {:error, res} =
      MyXQL.transaction(pid, fn conn ->
        MyXQL.query!(conn, statement, params)
        MyXQL.rollback(conn, :rolled_back)
      end)
1 Like