Skip to content

Pattern matching fails on nested map with values only as key #5602

@artemrizhov

Description

@artemrizhov

Environment

  • Erlang/OTP 19 [erts-8.2] [source-fbd2db2] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false]
  • Elixir 1.3.4
  • Operating system: Ubuntu 16.04

Current behavior

Error:

iex(57)> m = %{ %{1 => 2} => 3}  
%{%{1 => 2} => 3}
iex(58)> %{ %{1 => 2} => x} = m
** (CompileError) iex:58: only association operators '=>' are allowed in map construction

But this works:

iex(58)> key = %{1 => 2}
%{1 => 2}
iex(59)> %{ ^key => x} = m
%{%{1 => 2} => 3}
iex(60)> x
3

Expected behavior

Probably should work like in Erlang:

1> M = #{ #{1 => 2} => 3 }.
#{#{1 => 2} => 3}
2> #{ #{1 => 2} := X } = M.
#{#{1 => 2} => 3}
3> X.
3

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions