Elixir: Clause cannot match warning on line 1 after upgrading to elixir 1.6

Created on 18 Jan 2018  Â·  11Comments  Â·  Source: elixir-lang/elixir

Environment

  • Elixir & Erlang versions (elixir --version): 1.6.0 and 20
  • Operating system: macOS High Sierra 10.13.1

Current behavior

When compiling, the following module gives the warnings:

warning: this clause cannot match because a previous clause at line 1 always matches
  lib/re_web/router.ex:1

warning: this clause cannot match because a previous clause at line 1 always matches
  lib/re_web/router.ex:1

Here's the full module:

defmodule ReWeb.Router do
  use ReWeb, :router

  pipeline :browser do
    plug(:accepts, ["html"])
    plug(:fetch_session)
    plug(:fetch_flash)
    plug(:protect_from_forgery)
    plug(:put_secure_browser_headers)
  end

  pipeline :public_api do
    plug(:accepts, ["json"])
  end

  pipeline :private_api do
    plug(:accepts, ["json"])
    plug(ReWeb.GuardianPipeline)
  end

  scope "/", ReWeb do
    pipe_through(:public_api)

    resources("/neighborhoods", NeighborhoodController, only: [:index])
    resources("/listings", ListingController, only: [:index, :show])
    resources("/interests", InterestController, only: [:create])
    post("/users/login", AuthController, :login)
    post("/users/register", AuthController, :register)
  end

  scope "/", ReWeb do
    pipe_through(:private_api)

    resources "/listings", ListingController, except: [:new] do
      resources("/images", ImageController, only: [:index, :create, :delete])
    end

    put("/listings/:listing_id/image_order", ListingController, :order)
  end

  if Mix.env() == :dev do
    scope "/dev" do
      pipe_through(:browser)

      forward("/mailbox", Plug.Swoosh.MailboxPreview, base_path: "/dev/mailbox")
    end
  end
end

There's no warning in Elixir 1.5.2 and commenting out the line 25 (resources("/listings", ListingController, only: [:index, :show])) also removes the warning.

I'm also not sure if this belongs here or in Phoenix.

Expected behavior

Give warning on the proper line or no warning at all.

Most helpful comment

Fixed on Phoenix and back-ported to v1.3 there.

All 11 comments

I think that is because a bug was fixed. There is overlap in the calls between both of the "/listings" resources so that error 'should' have been there, but because of a bug it was not being shown before? Proper line would be much better though...

Good catch. I am on it. Let's see what we can do.

Fixed on Phoenix and back-ported to v1.3 there.

How can I update my phoenix 1.3 dep to use this commit? I ran mix deps.update phoenix and it didn't change the hash in my mix.lock…

Also tried

mix deps.unlock phoenix
mix deps.get

SInce it was not released yet, you need to move to a git dependency.

Is there a way to do that while making it so that my dependency that relies on phoenix 1.0 < x < 1.3 still work?

Try that out and mix should guide you to use the override: true option.

You will also need to pass the branch: "v1.3" option.

ok I'm using https://github.com/phoenixframework/phoenix/commit/c7a6569d3ef212599b0946f2e8585c7f3c034192 and I'm still getting:

warning: this clause cannot match because a previous clause at line 2 always matches
  lib/zipbooks_web/router.ex:2

warning: this clause cannot match because a previous clause at line 2 always matches
  lib/zipbooks_web/router.ex:2

warning: this clause cannot match because a previous clause at line 2 always matches
  lib/zipbooks_web/router.ex:2

warning: this clause cannot match because a previous clause at line 2 always matches
  lib/zipbooks_web/router.ex:2

warning: this clause cannot match because a previous clause at line 2 always matches
  lib/zipbooks_web/router.ex:2

warning: this clause cannot match because a previous clause at line 2 always matches
  lib/zipbooks_web/router.ex:2
defmodule ZB.Router do
  use Phoenix.Router <------ line 2
  use Plug.ErrorHandler
  use Sentry.Plug

I am trying to upgrade to Elixir 1.7 from 1.5.2 and still getting this warning (Phoenix 1.3)

warning: this clause cannot match because a previous clause at line 160 always matches
  lib/evercam_media_web/controllers/archive_controller.ex:190
warning: this clause cannot match because a previous clause at line 1 always matches
  lib/evercam_media_web/router.ex:1
warning: this clause cannot match because a previous clause at line 1 always matches
  lib/evercam_media_web/router.ex:1
warning: this clause cannot match because a previous clause at line 1 always matches
  lib/evercam_media_web/router.ex:1
warning: this clause cannot match because a previous clause at line 1 always matches
  lib/evercam_media_web/router.ex:1

@ijunaid8989 You should post support requests to the Elixir Forums, and for your issue you should definitely post your router.ex file in the post (with proper code fences). :-)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

whitepaperclip picture whitepaperclip  Â·  3Comments

alexrp picture alexrp  Â·  4Comments

cmeiklejohn picture cmeiklejohn  Â·  3Comments

GianFF picture GianFF  Â·  3Comments

ericmj picture ericmj  Â·  3Comments