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
  lib/list/chars.ex:1

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

...
warning: this clause cannot match because a previous clause at line 6 always matches
  lib/inspect.ex:6

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:

ERL_LIBS=/nix/store/h7zp9vg05m4jimbvp4d9majqnq4qa8jb-elixir-1.9.1/lib/elixir/lib:/nix/store/h7zp9vg05m4jimbvp4d9majqnq4qa8jb-elixir-1.9.1/lib/elixir/lib

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.

1 Like

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 https://github.com/NixOS/nixpkgs/blob/076860e0340a5e4a909b9a710e186508b14d1c90/pkgs/development/beam-modules/build-mix.nix#L41 and https://github.com/NixOS/nixpkgs/blob/076860e0340a5e4a909b9a710e186508b14d1c90/pkgs/development/interpreters/elixir/setup-hook.sh

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.