On the iex
console, I found the following error that I'm unsure what I've done wrong...
case %{} do
x when x == %{} -> true
_x -> false
end
Results in the following error:
** (ErlangError) erlang error: :guard_expr
Also, I wanted to explain how I found this. I attempted to make my own ||
macro by looking at elixir's implementation and changing it to treat []
, {}
, and %{}
the same as false
and nil
.
https://github.com/elixir-lang/elixir/blob/master/lib/elixir/lib/kernel.ex#L2313
Here's that implementation (it has the same problem):
defmodule Or do
defmacro left || right do
quote do
case unquote(left) do
x when x in [false, nil] or x == [] or x == {} or x == %{} ->
unquote(right)
x ->
x
end
end
end
end
Taking away the or x == %{}
makes things work.
This appears to be an Erlang bug. Here is the erlang code to reproduce the issue:
case #{} of X when X == #{} -> X end.
Thanks to everyone for confirming! See comments for more details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With