Skip to content

Commit 11b625a

Browse files
simeonschaubKristofferC
authored andcommitted
exempt begin and underscore from macro hygiene (#40280)
(cherry picked from commit a52b43d)
1 parent 79559ac commit 11b625a

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/macroexpand.scm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@
324324
m parent-scope inarg))
325325

326326
(define (resolve-expansion-vars- e env m parent-scope inarg)
327-
(cond ((or (eq? e 'end) (eq? e 'ccall) (eq? e 'cglobal))
327+
(cond ((or (eq? e 'begin) (eq? e 'end) (eq? e 'ccall) (eq? e 'cglobal) (underscore-symbol? e))
328328
e)
329329
((symbol? e)
330330
(let ((a (assq e env)))

test/syntax.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2674,3 +2674,15 @@ end == 4
26742674
@test ncalls_in_lowered(:(.!(1 .< A .< 2)), GlobalRef(Base, :materialize)) == 1
26752675
@test ncalls_in_lowered(:((.!)(1 .< A .< 2)), GlobalRef(Base, :materialize)) == 1
26762676
end
2677+
2678+
macro m_underscore_hygiene()
2679+
return :(_ = 1)
2680+
end
2681+
2682+
@test @macroexpand(@m_underscore_hygiene()) == :(_ = 1)
2683+
2684+
macro m_begin_hygiene(a)
2685+
return :($(esc(a))[begin])
2686+
end
2687+
2688+
@test @m_begin_hygiene([1, 2, 3]) == 1

0 commit comments

Comments
 (0)