Skip to content

Commit

Permalink
exempt begin and underscore from macro hygiene (#40280)
Browse files Browse the repository at this point in the history
  • Loading branch information
simeonschaub authored Mar 31, 2021
1 parent 15d876f commit a52b43d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/macroexpand.scm
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@
m parent-scope inarg))

(define (resolve-expansion-vars- e env m parent-scope inarg)
(cond ((or (eq? e 'end) (eq? e 'ccall) (eq? e 'cglobal))
(cond ((or (eq? e 'begin) (eq? e 'end) (eq? e 'ccall) (eq? e 'cglobal) (underscore-symbol? e))
e)
((symbol? e)
(let ((a (assq e env)))
Expand Down
12 changes: 12 additions & 0 deletions test/syntax.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2751,3 +2751,15 @@ end
@test eval(:(x = $(QuoteNode(Core.SlotNumber(1))))) == Core.SlotNumber(1)
@test_throws ErrorException("syntax: SSAValue objects should not occur in an AST") eval(:(x = $(Core.SSAValue(1))))
@test_throws ErrorException("syntax: Slot objects should not occur in an AST") eval(:(x = $(Core.SlotNumber(1))))

macro m_underscore_hygiene()
return :(_ = 1)
end

@test @macroexpand(@m_underscore_hygiene()) == :(_ = 1)

macro m_begin_hygiene(a)
return :($(esc(a))[begin])
end

@test @m_begin_hygiene([1, 2, 3]) == 1

0 comments on commit a52b43d

Please sign in to comment.