Compilation warnings (clause cannot match) in mix-and-otp tutorial

I’m going through the Mix and OTP tutorial and when I compile the project I see many compilation warnings for what appear to be redundant pattern-match clauses.

$ mix new kv --module KV
$ cd kv
$ mix compile
Compiling 1 file (.ex)
Generated kv app
warning: this clause cannot match because a previous clause at line 1 always matches

warning: this clause cannot match because a previous clause at line 1 always matches

warning: this clause cannot match because a previous clause at line 6 always matches

77 warning in total, though many are duplicates. Because I’m new to Elixir, I’d like to understand this before continuing. Specifically, I’m wondering:

  • Where (if anywhere) can I find the files it’s complaining about (e.g. lib/list/chars.ex)?
  • What (if anything) should I do to address these warnings?
  • Is this something I should report an issue for?

The guide lists the following version requirements:

  • Elixir 1.9.0 onwards
  • Erlang/OTP 20 onwards

I’m using Elixir 1.9.1 and Erlang/OTP 22

Erlang/OTP 22 [erts-10.4.3] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [hipe]

Elixir 1.9.1 (compiled with Erlang/OTP 22)

I’m running on NixOS, in case that’s relevant.

I’ve never seen those warnings in that context…

But the filenames mentioned in the warnings appear to be from the standard library.

But perhaps @DianaOlympos or @hauleth can help you, both of them use Nix as well as far as I can remember.

Yes it is. I am encountering the same issue. I haven’t dug what is the problem, but so far I just get used to ignoring it (everything works as expected). It is somehow related to the protocols, but I didn’t found the reason for that warnings yet.

It seems to be related to the ERL_LIBS environment variable.

I tried installing elixir systemwide in my nixos config rather than using nix-shell -p elixir and the compiler warnings disappeared. Comparing env inside and outside the nix-shell I noticed that in the nix-shell the environment had:


My first thought was that because the above contains the same path twice, something was loading twice, leading to the warnings. This was not the case, however – removing the duplicate entry had no effect.

Unsetting ERL_LIBS eliminated the warnings. I don’t know if it will break something else further down the line, but so far I’ve been able to use mix new, mix compile, and mix test without issue.


Is it maybe possible that you are using an elixir version that is compiled on one version of OTP, with another version of OTP? I believe you can see this info when running elixir --version.

Not so far as I can tell. It looks like it was compiled with and is using OTP 22

$ elixir --version
Erlang/OTP 22 [erts-10.4.3] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [hipe]

Elixir 1.9.1 (compiled with Erlang/OTP 22)
1 Like

It is not possible in Nix.

So you can keep ERL_LIBS but we should probably not get it in double. I think this come from and

I will check later and validate it is what is happening then push a patch.

I’m not sure this is NixOS related. I’m getting similar behaviour in Fedora 30 with Elixir packages built by asdf-vm. Unsetting ERL_LIBS does make the warnings go away. Seems to affect about any project (third-party or my own) EXCEPT for an umbrella app. Very strange.

I created Nix user repository mostly forked from beam modules from nixpkgs.

I unset ERL_LIBS from setup-hook and it seems that warnings have disappeared.

Try my repo