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