Skip to content

Commit

Permalink
fix #42220: macro hygiene with unary :: (#42221)
Browse files Browse the repository at this point in the history
(cherry picked from commit 8db1d89)
  • Loading branch information
simeonschaub authored and KristofferC committed Nov 11, 2021
1 parent 680bbce commit 0844d06
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
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 @@ -2704,3 +2704,14 @@ end
# issue #39705
@eval f39705(x) = $(Expr(:||)) && x
@test f39705(1) === false

# 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}

0 comments on commit 0844d06

Please sign in to comment.