Erlang/OTP 20 [erts-9.3] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:10] [hipe] [kernel-poll:false]
Elixir 1.6.4 (compiled with OTP 19)
CentOS 7 x86_64
This code doesn't compile
m = %{{1, 2} => 3}
a = 1
b = 2
%{{^a, ^b} => c} = m
** (CompileError) main.ex:4: illegal map key in pattern
It should compile.
FYI it works inside IEx:
$ iex
Erlang/OTP 20 [erts-9.3] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
Interactive Elixir (1.6.4) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> m = %{{1, 2} => 3}
%{{1, 2} => 3}
iex(2)> a = 1
1
iex(3)> b = 2
2
iex(4)> %{{^a, ^b} => c} = m
%{{1, 2} => 3}
iex(5)> c
3
iex(6)>
but not when compiling.
Thank you for the report @japplegame!
The raising is correct but the error message is not good. We will fix that.
@fertapric good catch. It works on IEx by accident. The Elixir expansion pass was supposed to catch it and raise. This is part of #5800.
@josevalim Why it shouldn't work?
This works:
d = {a, b}
%{^d => c} = m # the same as %{{^a, ^b} => c} = m
@liveforeverx as far as we are concerned, it is an Erlang compiler limitation. We need to ask them why. :)
Most helpful comment
@liveforeverx as far as we are concerned, it is an Erlang compiler limitation. We need to ask them why. :)