I have some AST rewriting code (using Sourceror) that has started failing in Elixir 1.18 – I believe because unquote has become stricter about valid AST, whereas in earlier versions it was only an issue within macros.
The issue is that it’s trying to generate code containing a ~D[...] sigil. It works in Elixir 1.17:
iex(1)> quote do: unquote(~D[2025-01-07])
** (ArgumentError) tried to unquote invalid AST: ~D[2025-01-07]
Did you forget to escape term using Macro.escape/1?
(elixir 1.18.1) src/elixir_quote.erl:542: :elixir_quote.argument_error/1
iex:1: (file)
I can use Macro.escape as suggested, but this inserts the date as a raw map instead of a sigil. This works, but doesn’t look great in the generated code:
The quote/unquote has nothing to do with how the final generated code looks like. They’re just means of generating AST/injecting given AST in the resulting AST. You’d need to figure out the correct AST you want to return for sourceror:
The quote/unquote has nothing to do with how the final generated code looks like. They’re just means of generating AST/injecting given AST in the resulting AST. You’d need to figure out the correct AST you want to return for sourceror: