Got an error with a typo, can the error message be improved - cannot invoke remote function :elixir_module.read_cache/2 inside a match

I got an error due to a typo, but the message is weird. Error message is missing context like line no, etc

Is this a bug or can the message be improved?

Erlang/OTP 25 [erts-13.1.1] [source] [64-bit] [smp:10:10] [ds:10:10:10] [async-threads:1] [jit] [dtrace]

Elixir 1.14.1 (compiled with Erlang/OTP 25)

== Compilation error in file lib/test_module.ex ==
** (CompileError) lib/test_module.ex:2: cannot invoke remote function :elixir_module.read_cache/2 inside a match
    (elixir 1.14.1) expanding macro: Kernel.def/2
    lib/test_module.ex:2: TestError (module)

Below is the code which causes the error.

defmodule TestError do
  def x() do
  = # <- is causing the error message
  def y() do
1 Like

In a nutshell, the first function is on the left side of =, which makes it a pattern and therefore it is invalid. But we can improve the error message here. I will push a fix soon.