Skip to content

Do not assign macro expansion counters to caller-supplied aliases - #16140

Merged
josevalim merged 3 commits into
elixir-lang:mainfrom
lukaszsamson:fix-alias-hygiene-macro-args
Nov 17, 2026
Merged

josevalim merged 3 commits into
elixir-lang:mainfrom
lukaszsamson:fix-alias-hygiene-macro-args

Conversation

@lukaszsamson

Copy link
Copy Markdown
Contributor

Closes #16139.

do_linify assigned the expansion counter to every alias/require/import and __aliases__ node in a macro expansion, including caller AST spliced in via unquote. A caller's alias (or the alias implied by defmodule) passed as a macro argument was therefore stored as a macro alias and could rebind the macro's own hygienic alias references.

The counter is now assigned only to nodes that come from a quote: directives carrying context metadata and aliases carrying the alias annotation.

Directives built by hand without context metadata no longer receive the counter. Aliases emitted by a macro still affect caller code.

Assisted-by: Codex:GPT-6
Assisted-by: Claude Code:claude-fable-5-2

@josevalim

Copy link
Copy Markdown
Member

@lukaszsamson do we need these extensive tests as well? Are they covering scenarios we haven't yet? Or should we have a minimal test that matches only the regression?

@josevalim
josevalim merged commit 9b1dfe3 into elixir-lang:main Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Alias in a macro argument breaks macro hygiene

2 participants