Skip to content

Commit a52b43d

Browse files
authored
exempt begin and underscore from macro hygiene (#40280)
1 parent 15d876f commit a52b43d

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
@@ -2751,3 +2751,15 @@ end
27512751
@test eval(:(x = $(QuoteNode(Core.SlotNumber(1))))) == Core.SlotNumber(1)
27522752
@test_throws ErrorException("syntax: SSAValue objects should not occur in an AST") eval(:(x = $(Core.SSAValue(1))))
27532753
@test_throws ErrorException("syntax: Slot objects should not occur in an AST") eval(:(x = $(Core.SlotNumber(1))))
2754+
2755+
macro m_underscore_hygiene()
2756+
return :(_ = 1)
2757+
end
2758+
2759+
@test @macroexpand(@m_underscore_hygiene()) == :(_ = 1)
2760+
2761+
macro m_begin_hygiene(a)
2762+
return :($(esc(a))[begin])
2763+
end
2764+
2765+
@test @m_begin_hygiene([1, 2, 3]) == 1

0 commit comments

Comments
 (0)