Incorrect compiler error (wrong source file)

I’m getting this error:

warning: variable "params" is unused
  lib/supervisor.ex:57

But there is no lib/supervisor.ex in my project. There is lib/master_monitor.ex which on line 57 has an unused params variable. That source file has 3 modules defined in it; the error is in the second module; that module uses Supervisor; and the error is in its init callback. So I can kind of get a feel for how the compiler could go wrong in reporting the source file.

I don’t think it would be trivial to reduce this to a minimal repro case. Is there some other info I could provide? (I could always provide a slightly stripped-down project even if not minimal…)

This is with 1.4.1, BTW.

1 Like

That’s not an error but a warning. Errors cancel compilation and you have to fix them to get something executable, warnings are just remarks, which you should fix but not necessarily need to [1].

Hava you checked if this warning is really from your project or from one of your dependencies? Does this warning disappear when you prefix that params variable in your file with an underscore (making it _params)?

Also it would be nice to show some code that reproduces that problem to make sure if there is a bug in the compiler or not.

[1] Right now. It’s good style to clean them up though.

2 Likes

Yes, the warning is from my code, exactly as described.

1 Like

So you have to provide code so we can dig deeper into this.

1 Like

OK, I’ll work on stripping down the project reasonably.

1 Like

Well, I hacked away code, and found that it apparently doesn’t have the kind of complicated dependency I was imagining. Just put this code into lib/monitor_target.ex, and the compiler will warn of unused params in lib/supervisor.ex:

defmodule Monitor.Target do
  use Supervisor

  def start_link(fubar) do
    Supervisor.start_link(__MODULE__, [fubar])
  end

  def init([_] = params) do
  end

end
1 Like

(But the line number is correct for monitor_target.ex)

1 Like

I have modified your example a bit and removed the pattern match and only left the binding.

And in fact it seems as if you have discovered a regression from 1.3.4 to 1.4.0:

$ cat foo.exs
defmodule Foo do
  use Supervisor

  def start_link(fubar) do
    Supervisor.start_link(__MODULE__, [fubar])
  end

  def init(params) do
  end
end

$ kiex use 1.3.4
Using 1.3.4

$ elixir foo.exs
warning: variable params is unused
  foo.exs:8

$ kiex use 1.4.0
Using 1.4.0

$ elixir foo.exs
warning: variable "params" is unused
  lib/supervisor.ex:8

As a quick guess, I might think it was introduced by c69fa11, but I am not quite sure.

I will file an issue at github

1 Like

Thanks.

1 Like

Thanks for the bug report. This PR should fix it.

2 Likes