3

I am getting a dialyzer error about unmatched returns of which I'm not sure how to properly address.

mix dialyzer --quiet
lib/my_app_web/router.ex:1:no_return
Function __checks__/0 has no local return.
________________________________________________________________________________
lib/my_app_web/router.ex:21:unmatched_return
The expression produces a value of type:

%{
  :adapter => _,
  :before_send => _,
  :content_type => _,
  :context => _,
  :document_providers => _,
  :json_codec => _,
  :log_level => _,
  :no_query_message => _,
  :pipeline => _,
  :pubsub => _,
  :raw_options => Keyword.t(),
  :schema_mod => atom(),
  :serializer => _
}

but this value is unmatched.

________________________________________________________________________________
lib/my_app_web/router.ex:24:unmatched_return
The expression produces a value of type:

%{
  :adapter => _,
  :additional_pipeline => _,
  :assets => _,
  :before_send => _,
  :content_type => _,
  :context => _,
  :default_headers => _,
  :default_url => _,
  :document_providers => _,
  :interface => _,
  :json_codec => _,
  :log_level => _,
  :no_query_message => _,
  :pipeline => {Absinthe.Plug.GraphiQL, :pipeline},
  :pubsub => _,
  :raw_options => [{_, _}],
  :schema_mod => atom(),
  :serializer => _,
  :socket => _,
  :socket_url => _
}

but this value is unmatched.

My mix.exs looks like this:

  def project do
    [
      app: :my_app,
      version: "0.1.0",
      elixir: "1.9.4",
      elixirc_paths: elixirc_paths(Mix.env()),
      compilers: [:phoenix, :gettext] ++ Mix.compilers(),
      start_permanent: Mix.env() == :prod,
      dialyzer: [
        plt_add_deps: :transitive,
        flags: [:error_handling, :race_conditions, :unmatched_returns, :underspecs]
      ],
      aliases: aliases(),
      deps: deps()
    ]
  end

my router.ex looks like this:

defmodule MyAppWeb.Router do
  use MyAppWeb, :router

  pipeline :browser do
    plug :accepts, ["html"]
    plug :fetch_session
    plug :fetch_flash
    plug :protect_from_forgery
    plug :put_secure_browser_headers
    plug MyAppWeb.Auth
  end

  pipeline :api do
    plug :accepts, ["json"]
  end

  # Other scopes may use custom stacks.
  scope "/api" do
    pipe_through :api

    forward "/graphql", Absinthe.Plug, schema: MyAppWeb.Schema.UserTypes

    if Mix.env() == :dev do
      forward "/graphiql", Absinthe.Plug.GraphiQL,
        schema: MyAppWeb.Schema.UserTypes,
        interface: :simple
    end
  end

  scope "/", MyAppWeb do
    pipe_through :browser

    resources "/users", UserController,
      only: [:index, :show, :new, :create, :edit, :delete, :update]

    resources "/sessions", SessionController, only: [:new, :create, :delete]

    get "/", PageController, :index, as: :home

    get "/*path", PageController, :index
  end
end

I have tried the _ = trick but it doesn't seem to work. I think using unmatched returns could be helpful but perhaps not in this case. I have read this page (https://github.com/jeremyjh/dialyxir/wiki/Phoenix-Dialyxir-Quickstart) but I don't think it helped fix this issue.

Any feedback or direction would be greatly appreciated.

Thank you

Adam Millerchip
  • 20,844
  • 5
  • 51
  • 74
Loading...
  • 863
  • 9
  • 21

1 Answers1

3

I found out that the issue comes from this phoenix commit: https://github.com/phoenixframework/phoenix/commit/b10fb7dc33a198595872b783cbbf90f1daee91ba

It can be either Phoenix issue or Absinthe.Plug.init/1 specs that cause the warning.

For the time issue is being resolved you could use ignore warnings features from Dialyxir: https://github.com/jeremyjh/dialyxir#ignore-warnings

bartek
  • 31
  • 2