Skip to content

Handle escaped module names from Julia 1.12 hygienic macro expansion#36

Open
PatrickHaecker wants to merge 4 commits into
JuliaPluto:mainfrom
PatrickHaecker:escape_module_julia_1.12
Open

Handle escaped module names from Julia 1.12 hygienic macro expansion#36
PatrickHaecker wants to merge 4 commits into
JuliaPluto:mainfrom
PatrickHaecker:escape_module_julia_1.12

Conversation

@PatrickHaecker

@PatrickHaecker PatrickHaecker commented Apr 6, 2026

Copy link
Copy Markdown

Julia 1.12 wraps module names in Expr(:escape, :Name) during hygienic
macro expansion. This caused explore_module! to fail because it expected
a bare Symbol in the module name position.

Use unescape() to unwrap the module name before recording it as an
assignment, with a guard for non-Symbol results.

Also widen Aqua test compat to include v1 in the second commit. I can remove this change, if it is not welcomed.

This change was needed to make a notebook work with Julia 1.12 which worked previously without the change with Julia 1.11.

I used Claude Opus 4.6 to create the commit and fine-tuned it afterwards.

Patrick Häcker added 2 commits April 6, 2026 06:59
Julia 1.12 wraps module names in Expr(:escape, :Name) during hygienic
macro expansion. This caused explore_module! to fail because it expected
a bare Symbol in the module name position.

Use unescape() to unwrap the module name before recording it as an
assignment, with a guard for non-Symbol results.
@fonsp

fonsp commented Apr 9, 2026

Copy link
Copy Markdown
Member

Thanks for your PR! Would it be possible to write a more realistic test case? You could make a macro, and then let Julia macroexoand it and test the result.

Replace the manually constructed `Expr(:module, true, Expr(:escape, :a), ...)`
test with a macro + macroexpand test mimicking `@enumx`, as suggested by fonsp.
On Julia 1.12, macros that use `esc()` with `:toplevel` produce
`Expr(:escape, :Name)` inside `Expr(Symbol("hygienic-scope"), ...)` after
`macroexpand`.
@PatrickHaecker

Copy link
Copy Markdown
Author

Something like the most recent commit? If not, please feel free to suggest test code directly.

For reference, I observed the original problem when using EnumX.jl in a (proprietary) notebook with Julia 1.12.

@fonsp

fonsp commented Apr 20, 2026

Copy link
Copy Markdown
Member

Thanks! Did you change from @test testee to @test_nowarn on purpose?

@PatrickHaecker

Copy link
Copy Markdown
Author

Thanks, @fonsp. I hadn't really understood the @test testee and when it stopped working I quickly used what I know. But I now took some time to understand this better and adapted the style slightly to match the existing code better.

I hope this is a step in the right direction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants