Hmmm, the full stack trace is interesting:
iex(7)> :ets.fun2ms(fn {x,y,z,:_} when x == id or y == id -> {x,y,z} end)
** (FunctionClauseError) no function clause matching in :ms_transform.normalise/1
The following arguments were given to :ms_transform.normalise/1:
# 1
{:EXIT,
{:badarg,
[
{:lists, :keysearch, [:_@0, 1, %{_@0: 4}],
[error_info: %{module: :erl_stdlib_errors}]},
{:ms_transform, :fixup_environment, 2,
[file: 'ms_transform.erl', line: 1104]},
{:lists, :map_1, 2, [file: 'lists.erl', line: 1320]},
{:lists, :map, 2, [file: 'lists.erl', line: 1315]},
{:lists, :map_1, 2, [file: 'lists.erl', line: 1320]},
{:lists, :map_1, 2, [file: 'lists.erl', line: 1320]},
{:lists, :map, 2, [file: 'lists.erl', line: 1315]},
{:ms_transform, :fixup_environment, 2,
[file: 'ms_transform.erl', line: 1112]}
]}}
(stdlib 4.1.1) ms_transform.erl:1124: :ms_transform.normalise/1
(stdlib 4.1.1) ms_transform.erl:222: :ms_transform.transform_from_shell/3
(stdlib 4.1.1) ets.erl:605: :ets.fun2ms/1
iex:7: (file)
There’s actually TWO crashes happening here:
:ms_transform.normalize is being called with an {:EXIT, ...etc} tuple because the error handling in transform_from_shell wasn’t expecting that shape:
https://github.com/erlang/otp/blob/d95d79d1e363879462d9775316896c02b59771ee/lib/stdlib/src/ms_transform.erl#L217-L225
- that tuple is coming from
:ms_transform.fixup_environment, which expects an environment B as a keyword list but gets a map instead:
https://github.com/erlang/otp/blob/d95d79d1e363879462d9775316896c02b59771ee/lib/stdlib/src/ms_transform.erl#L1103-L1109
The root cause is that :erl_eval.fun_data/1 is returning a map for the bound variables
:
iex(9)> :erl_eval.fun_data(fn {x,y,z,:_} when x == id or y == id -> {x,y,z} end)
{:fun_data, %{_@0: 4},
[
{:clause, 9,
[
{:tuple, 9,
[{:var, 9, :_x@1}, {:var, 9, :_y@1}, {:var, 9, :_z@1}, {:atom, 9, :_}]}
],
[
[
{:op, 9, :orelse, {:op, 9, :==, {:var, 9, :_x@1}, {:var, 9, :_@0}},
{:op, 9, :==, {:var, 9, :_y@1}, {:var, 9, :_@0}}}
]
], [{:tuple, 9, [{:var, 9, :_x@1}, {:var, 9, :_y@1}, {:var, 9, :_z@1}]}]}
]}