Dialyxir and new supervisor syntax error

Hello everyone,

I receive the following error message from dialyxir.

lib/otp/worker_sup.ex:10: Function init/1 has no local return
lib/otp/worker_sup.ex:16: The call 'Elixir.Supervisor':init(Vchildren@1::[{_,_},...],Vopts@1::[{'strategy','simple_one_for_one'},...]) breaks the contract ([supervisor:child_spec() | {module(),term()} | module()],[init_option()]) -> {'ok',tuple()}

The code is as follow

defmodule Otp.WorkerSup do
  use Supervisor
  alias __MODULE__

  @spec start_link(mfa()) :: {:ok, pid()} | {:error, term()}
  def start_link({_, _, _} = mfa) do
    Supervisor.start_link(WorkerSup, mfa, name: WorkerSup)
  end

  def init({m, _f, a}) do
    children = [
      {m, a}
    ]

    opts = [strategy: :simple_one_for_one]
    Supervisor.init(children, opts)
  end
end

It is a simple supervisor for spawning workers.

I tried to fake a response, by adding {:ok, {}} at the end of the init function, but it does not change the error.

I am running this on Elixir 1.6 otp, Erlang 20.1

BTW the code is running fine, I just would like to know how to resolve dialyxir error message.

Any ideas?

Thanks for taking time

:strategy is of type Supervisor.strategy/0, which is an enumeration of :one_for_one, :one_for_all and :rest_for_one but not :simple_one_for_one.

So dialyzer will complain about it.

There is a deprecation note:

There is also a deprecated strategy called :simple_one_for_one which has been replaced by the DynamicSupervisor

So you have to live with the dialyzer warnings and probably runtime deprecation warnings in the future or you rewrite in favor of the DynamicSupervisor

4 Likes

Thank You for the explanation.