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

fix #42220: macro hygiene with unary :: #42221

Merged
merged 1 commit into from
Sep 14, 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
23 changes: 15 additions & 8 deletions src/macroexpand.scm
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,9 @@
(define (other x) (resolve-expansion-vars-with-new-env x env m parent-scope inarg))
(case (car e)
((where) `(where ,(recur (cadr e)) ,@(map other (cddr e))))
((|::|) `(|::| ,(recur (cadr e)) ,(other (caddr e))))
((|::|) (if (length= e 2)
`(|::| ,(other (cadr e)))
`(|::| ,(recur (cadr e)) ,(other (caddr e)))))
((call) `(call ,(other (cadr e))
,@(map (lambda (x)
(resolve-expansion-vars-with-new-env x env m parent-scope #t))
Expand Down Expand Up @@ -397,13 +399,18 @@
((not (length> e 2)) e)
((and (pair? (cadr e))
(eq? (caadr e) '|::|))
`(kw (|::|
,(if inarg
(resolve-expansion-vars- (cadr (cadr e)) env m parent-scope inarg)
;; in keyword arg A=B, don't transform "A"
(unescape (cadr (cadr e))))
,(resolve-expansion-vars- (caddr (cadr e)) env m parent-scope inarg))
,(resolve-expansion-vars-with-new-env (caddr e) env m parent-scope inarg)))
(let* ((type-decl (cadr e)) ;; [argname]::type
(argname (and (length> type-decl 2) (cadr type-decl)))
(type (if argname (caddr type-decl) (cadr type-decl))))
`(kw (|::|
,@(if argname
(list (if inarg
(resolve-expansion-vars- argname env m parent-scope inarg)
;; in keyword arg A=B, don't transform "A"
(unescape argname)))
'())
,(resolve-expansion-vars- type env m parent-scope inarg))
,(resolve-expansion-vars-with-new-env (caddr e) env m parent-scope inarg))))
(else
`(kw ,(if inarg
(resolve-expansion-vars- (cadr e) env m parent-scope inarg)
Expand Down
11 changes: 11 additions & 0 deletions test/syntax.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2966,3 +2966,14 @@ end

@generated g25678(x) = return :x
@test g25678(7) === 7

# issue 42220
macro m42220()
return quote
function foo(::Type{T}=Float64) where {T}
return Vector{T}(undef, 10)
end
end
end
@test @m42220()() isa Vector{Float64}
@test @m42220()(Bool) isa Vector{Bool}