Elixir: Internal Consistency Error

Created on 13 Apr 2020  路  2Comments  路  Source: elixir-lang/elixir

Precheck

Environment

  • Elixir & Erlang/OTP versions (elixir --version):
Erlang/OTP 22 [erts-10.4.4] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [hipe]

Elixir 1.9.4 (compiled with Erlang/OTP 22)
  • Operating system:
    OS X

Current behavior

This code:

      for event_type <- @important_events,
          events = Map.get(grouped_events, event_type, []) != [],
          reduce: shipment do
        shipment ->
          _ = handle_event(event_type, shipment, events, org, user)
          {:ok, shipment} = lookup_shipment(org, user, shipment["id"])
          shipment
      end

(I do realize this has a bug, the events variable would be a boolean and not the events list I expect).

produces:

== Compilation error in file lib/my_app/some_file.ex ==
** (CompileError) Elixir.MyApp.Module: function handle_event/5+2:
  Internal consistency check failed - please report this bug.
  Instruction: {func_info,{atom,'Elixir.MyApp.SomeFile'},
                          {atom,handle_event},
                          5}
  Error:       {uninitialized_reg,{x,3}}:

    (stdlib) lists.erl:1338: :lists.foreach/2
    (elixir) src/elixir_erl_compiler.erl:12: anonymous fn/3 in :elixir_erl_compiler.spawn/2

Curiously, I can make the error go away by doing:

      for event_type <- @important_events,
          events = Map.get(grouped_events, event_type, []) != [],
          reduce: shipment do
        shipment ->
          events = Map.get(grouped_events, event_type) || []
          _ = handle_event(event_type, shipment, events, org, user)
          {:ok, shipment} = lookup_shipment(org, user, shipment["id"])
          shipment
      end

Where I repeat the events = Map.get(grouped_events, event_type) || [] line _inside_ the for block.

The issue also goes away if I write a non buggy version of the for comprehension:

      for event_type <- @important_events,
          events = Map.get(grouped_events, event_type, []),
          events != [],
          reduce: shipment do
Erlang bug Needs more info

Most helpful comment

I could reproduce and I have verified it is fixed in OTP 23.

All 2 comments

Please provide more information on how we can fully reproduce this as I cannot reproduce it locally with the provided samples. Thanks.

I could reproduce and I have verified it is fixed in OTP 23.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

michalmuskala picture michalmuskala  路  35Comments

josevalim picture josevalim  路  44Comments

dmorneau picture dmorneau  路  30Comments

josevalim picture josevalim  路  41Comments

wojtekmach picture wojtekmach  路  34Comments