Macro.escape/2 unquote option behaviour in Elixir 1.19

Hi, I noticed Absinthe tests failing when using Elixir 1.19.0-rc.2. After some investigation the issue seems to be a change in behaviour of Macro.escape/2 when using the :unquote option. For example, evaluating this expression:

iex> Macro.escape(%{field: {:unquote, [], [:test]}}, unquote: true)

Elixir 1.18: {:%{}, [], [field: :test]}
Elixir 1.19: {:%{}, [], [field: {:{}, [], [:unquote, [], [:test]]}]}

It seems that in 1.19 the unescaping only works when the parent node doesn’t need escaping. Macro.escape([{:unquote, [], [:test]}], unquote: true) for example results in [:test]

I noticed the added line in the documentation “Note this option will give a special meaning to quote/unquote nodes, which need to be valid AST before escaping.”, but to me it’s not entirely clear if this is the intended behaviour, as it is a breaking change, so I was wondering if anybody can confirm this is expected?

2 Likes

I assume this PR is involved? It’s also the source of that docs change.

Yeah, I’m pretty sure this PR caused the change, but I didn’t have the time to properly look into it in order to be sure if this is intended, so that’s why I asked here.

1 Like

Oddly enough, wrapping the bare term in a list seems to work:

Macro.escape(%{field: [{:unquote, [], [:test]}]}, unquote: true)
{:%{}, [], [field: [:test]]}

Woops, good catch @zambal! :purple_heart:

Created an issue, Macro.escape/2 doesn't honor :unquote option inside maps on 1.19rc · Issue #14829 · elixir-lang/elixir · GitHub.

1 Like