$ elixir --version
Erlang/OTP 23 [erts-11.0] [source] [64-bit] [smp:16:16] [ds:16:16:10] [async-threads:1] [hipe] [dtrace]
Elixir 1.10.3 (compiled with Erlang/OTP 22)
Given the following in code in test.exs:
map = %{"a" => 1}
case map["a"] do
_ ->
%{map | a: 2}
end
Running the script produces the following error:
$ elixir test.exs
** (KeyError) key :a not found
test.exs:2: (file)
(elixir 1.10.3) lib/code.ex:926: Code.require_file/2
The error is reported as occurring on line 2 (the case) instead of the actual location of the issue, line 4. Additionally, changing line 2 of the test file to case map do results in the error being reported as occurring on line 2, even though the actual problem is still line 4.
In both case the error should be reported as occurring on line 4.
Unfortunately there is nothing we can do here. %{ | } compiles to bytecode operation and, according to my understanding, those do not get line numbers as they do not add stacktrace entries (it is one of the reasons why they are faster).
This looks like a bug in the Erlang compiler. Reported upstream as https://bugs.erlang.org/browse/ERL-1271
Most helpful comment
Fixed in https://github.com/erlang/otp/pull/2647