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)
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
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.
Most helpful comment
I could reproduce and I have verified it is fixed in OTP 23.