Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exempt begin and underscore from macro hygiene #40280

Merged
merged 1 commit into from
Mar 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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