The Wire · Showcase
MACRO.TO_STRING BUG BREAKS FOR COMPREHENSIONS WITH TRAILING KEYWORDS
By RepoJournal · Filed · About Elixir & Phoenix
Elixir's Macro.to_string/1 silently corrupts for-comprehensions that use do-end blocks with non-block trailing keywords, rendering valid code that no longer compiles.
When Macro.to_string/1 encounters a trailing keyword list starting with do:, it renders the entire expression as a do-end block regardless of what comes after [1]. This breaks code like for(cp <- gc, do: <<cp::utf8>>, into: "") by parsing into as a bare variable instead of a comprehension option [1]. The rendered output looks syntactically valid but fails to compile, turning a silent macro bug into a runtime trap [2]. The fix restricts do-end block rendering to cases where every trailing keyword is actually a block keyword, preserving the semantic meaning of the original quoted expression [2]. This lands as a single commit across the Elixir repo over the last 24 hours.
One email a day. Unsubscribe in one click.
Keep up with Elixir & Phoenix in about 3 minutes a day: what actually shipped — the commits, pull requests, releases, and security advisories that matter.
One email a day. Unsubscribe in one click. Read a past issue →
Action items
- → Pull latest Elixir main if you work with for-comprehensions and Macro.to_string elixir-lang/elixir [plan]
- → Audit any macros that quote for-comprehensions with into: or other trailing keywords elixir-lang/elixir [monitor]
References
- [1] Only use do-end blocks when every trailing keyword is a block keyword ↗ elixir-lang/elixir
- [2] Only use do-end blocks when every trailing keyword is a block keyword (#15725) elixir-lang/elixir