Elixir: Incorrect line number reported for error when updating map inside case

Created on 1 Jun 2020  路  3Comments  路  Source: elixir-lang/elixir

Environment

  • Elixir & Erlang/OTP versions (elixir --version):
$ 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)
  • Operating system:
    macOS 10.15.3

Current behavior

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.

Expected behavior

In both case the error should be reported as occurring on line 4.

Elixir (compiler) Bug Unresolved

Most helpful comment

All 3 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

andrewcottage picture andrewcottage  路  3Comments

ghost picture ghost  路  4Comments

josevalim picture josevalim  路  3Comments

DEvil0000 picture DEvil0000  路  3Comments

Irio picture Irio  路  3Comments