Skip to content

Commit ff33305

Browse files
mlechudralletje
andauthored
Fix hygienic-scopes in inner macro expansions (#58965)
Changes from #43151, github just didn't want me to re-open it. As discussed on slack, any `hygienic-scope` within an outer `hygienic-scope` can read and write variables in the outer one, so it's not particularly hygienic. The result is that we can't safely nest macro calls unless they know the contents of all inner macro calls. Should fix #48910. Co-authored-by: Michiel Dral <m.c.dral@gmail.com>
1 parent 3847ff1 commit ff33305

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/macroexpand.scm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@
513513
(body (cadr e))
514514
(m (caddr e))
515515
(lno (cdddr e)))
516-
(resolve-expansion-vars-with-new-env body env m lno parent-scope inarg #t)))
516+
(resolve-expansion-vars-with-new-env body '() m lno parent-scope inarg #t)))
517517
((tuple)
518518
(cons (car e)
519519
(map (lambda (x)

test/core.jl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2280,6 +2280,31 @@ end
22802280
x6074 = 6074
22812281
@test @X6074() == 6074
22822282

2283+
# issues #48910, 54417
2284+
macro X43151_nested()
2285+
quote my_value = "from_nested_macro" end
2286+
end
2287+
macro X43151_parent()
2288+
quote
2289+
my_value = "from_parent_macro"
2290+
@X43151_nested()
2291+
my_value
2292+
end
2293+
end
2294+
@test @X43151_parent() == "from_parent_macro"
2295+
2296+
macro X43151_nested_escaping()
2297+
quote $(esc(:my_value)) = "from_nested_macro" end
2298+
end
2299+
macro X43151_parent_escaping()
2300+
quote
2301+
my_value = "from_parent_macro"
2302+
@X43151_nested_escaping()
2303+
my_value
2304+
end
2305+
end
2306+
@test @X43151_parent_escaping() == "from_nested_macro"
2307+
22832308
# issue #5536
22842309
test5536(a::Union{Real, AbstractArray}...) = "Splatting"
22852310
test5536(a::Union{Real, AbstractArray}) = "Non-splatting"

0 commit comments

Comments
 (0)