Skip to content

Commit

Permalink
fix JuliaLang#42220: macro hygiene with unary :: (JuliaLang#42221)
Browse files Browse the repository at this point in the history
  • Loading branch information
simeonschaub authored Sep 14, 2021
1 parent 2f47dae commit 8db1d89
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 @@ -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}

0 comments on commit 8db1d89

Please sign in to comment.