Dialyzer a function in application.ex "will never be called"

I’ve got a runtime config which has

# runtime.exs

if config_env() == :prod do
  config :some_app, start_gen_server: true

Then in my application.ex I have

  # application.ex

  def start(_type, _args) do
    |> maybe_start_gen_server()
    |> Supervisor.start_link(strategy: :one_for_one, name: MyApp.Supervisor)

  defp maybe_start_gen_server(children) do
    if Application.get_env(:some_app, :start_gen_server) do
      children ++ [MyApp.SomeGenServer]

Running mix dialyzer --force-check; I get

Function maybe_start_gen_server/1 will never be called.

and there’s not any other error or warning regarding this.
I’ve actually tested and confirmed that it’s actually called and my GenServer is running properly on production. What might be wrong?

It seems the condition is always truthy.

But still that’s inside the function maybe_start_gen_server so how is it possible for the function not to be called? In fact, I’d tested it and it was working on production env. Now I can’t test because of some other error but I’ll double check.

This sometimes means that a function call inside your function can raise an error.

But only function inside my function is the Application.get_env. Maybe I am doing something else wrong but as I’d mentioned above I’d tested the GenServer and it was working. I still can’t double check though because of some DB issue. So I’ll update here once I double check.

I figured if I make the function public instead of private then I don’t get the error. What’s the relation? :thinking:

Dialyzer doesn’t warn never-called on public functions, since they may be used in another application or be called dynamically.


Oh I didn’t know that, makes sense.
Still I have no idea why I get the warning when the function is private though.
I double checked it and it runs on production, meaning that the function is called. :thinking:

You’re executing dialyzer in dev mode. Presumably dialyzer is right and that function will never be called.

Perhaps the functioncall got inlined? Have you checked the Erlang core/ASM?