elixirdialyzer

How to fix Dialyzer "Callback info about the '.....' behaviour is not available" error for new Mix.Tasks


I created new Mix.Task in /lib/mix/tasks/start.ex for my project

defmodule Mix.Tasks.Start do
  use Mix.Task

  def run(_), do: IO.puts("Hello, World!")
end

Now, it could be run from console like this :
mix start

But I'm getting Dialyzer error, that Callback info about the 'Elixir.Mix.Task' behaviour is not available. What does it mean and how this could be fixed?


Solution

  • Looks like I didn't have Persistent Lookup Table (PLT) options added for dialyzer. In my case for 'Elixir.Mix.Task' behavior to be available for dialyzer I had to update mix.exs file and define for which modules dialyzer should create PLT.

      def project do
        [
          app: :some_app,
          version: "0.1.0",
          elixir: "~> 1.6",
          start_permanent: Mix.env() == :prod,
          deps: deps(),
          # Added following line
          dialyzer: [plt_add_apps: [:mix]]
        ]
      end
    

    dialyzer is added through dialyxir in same mix.exs file like this

      defp deps do
        [
          {:dialyxir, "~> 0.5", only: [:dev], runtime: false}
        ]
      end
    

    mix do deps.get, deps.compile
    And your dialyzer should stop complaining:
    mix dialyzer