I’ve been reading a great AST guide that I really recommend.
One of the examples given in the first part correctly states that…
quote do
Foo.{Bar, Baz}
end
#=>
{
{:., [], [{:__aliases__, [], [:Foo]}, :{}]},
[],
[{:__aliases__, [], [:Bar]}, {:__aliases__, [], [:Baz]}]
}
There is an explanation given in the guide as to why the form [alias, :{}] is used, but I don’t really understand why there would be ambiguity in using the form below…
quote do
Foo.{Bar, Baz}
end
#=>
{
:.,
[],
[
{:__alias__, [], [:Foo]},
{:{}, [], [{:__alias__, [], [:Bar]}, {:__alias__, [], [:Baz]}]}
]
}
I put the above hypothetical AST in a Macro.to_string call, and I got the following error.
** (CaseClauseError) no case clause matching: :Bar
(elixir 1.16.0) lib/code/formatter.ex:2319: Code.Formatter.force_args?/2
(elixir 1.16.0) lib/code/formatter.ex:1172: Code.Formatter.call_args_to_algebra_no_blocks/6
(elixir 1.16.0) lib/code/formatter.ex:1109: Code.Formatter.call_args_to_algebra/6
(elixir 1.16.0) lib/code/formatter.ex:1056: Code.Formatter.local_to_algebra/5
(elixir 1.16.0) lib/code/formatter.ex:1695: anonymous fn/5 in Code.Formatter.args_to_algebra_with_comments/7
(elixir 1.16.0) lib/code/formatter.ex:1998: Code.Formatter.each_quoted_to_algebra_without_comments/4
(elixir 1.16.0) lib/code/formatter.ex:1984: Code.Formatter.quoted_to_algebra_with_comments/6
iex:33: (file)
Is my AST not correct?