Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clause cannot match warning on line 1 after upgrading to elixir 1.6 #7224

Closed
rhnonose opened this issue Jan 18, 2018 · 12 comments
Closed

Clause cannot match warning on line 1 after upgrading to elixir 1.6 #7224

rhnonose opened this issue Jan 18, 2018 · 12 comments

Comments

@rhnonose
Copy link
Contributor

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.

@OvermindDL1
Copy link
Contributor

OvermindDL1 commented Jan 18, 2018

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...

@josevalim
Copy link
Member

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

@josevalim
Copy link
Member

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

@atomkirk
Copy link
Contributor

atomkirk commented Feb 21, 2018

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

@josevalim
Copy link
Member

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

@atomkirk
Copy link
Contributor

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?

@josevalim
Copy link
Member

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

@josevalim
Copy link
Member

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

@atomkirk
Copy link
Contributor

atomkirk commented Feb 21, 2018

ok I'm using phoenixframework/phoenix@c7a6569 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

@ijunaid8989
Copy link

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

@OvermindDL1
Copy link
Contributor

OvermindDL1 commented Jul 31, 2018

@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). :-)

@nelsonic
Copy link

nelsonic commented Dec 9, 2022

Getting this error on a fresh Phoenix 1.7 app: dwyl/phoenix-todo-list-tutorial#59 (comment)

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

router.ex file is: github.com/dwyl/phoenix-todo-list-tutorial/blob/main/lib/app_web/router.ex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

6 participants