Skip to content

Commit

Permalink
fix JuliaLang#36272: Error with optional argument in anonymous functi…
Browse files Browse the repository at this point in the history
…on defined in macro (JuliaLang#36273)
  • Loading branch information
simeonschaub committed Jun 15, 2020
1 parent 25dc696 commit 8d91b11
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/macroexpand.scm
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@
((atom? v) '())
(else
(case (car v)
((... kw |::|) (try-arg-name (cadr v)))
((... kw |::| =) (try-arg-name (cadr v)))
((escape) (list v))
((hygienic-scope) (try-arg-name (cadr v)))
((meta) ;; allow certain per-argument annotations
Expand Down Expand Up @@ -275,6 +275,9 @@
,@(map (lambda (x)
(resolve-expansion-vars-with-new-env x env m parent-scope #t))
(cddr e))))
((tuple) `(tuple ,@(map (lambda (x)
(resolve-expansion-vars-with-new-env x env m parent-scope #t))
(cdr e))))
(else (other e))))

(define (new-expansion-env-for x env (outermost #f))
Expand Down Expand Up @@ -367,7 +370,7 @@
(resolve-expansion-vars- x env m parent-scope #f)))
(cdr e))))

((= function)
((= function ->)
(if (and (pair? (cadr e)) (function-def? e))
;; in (kw x 1) inside an arglist, the x isn't actually a kwarg
`(,(car e) ,(resolve-in-function-lhs (cadr e) env m parent-scope inarg)
Expand Down
6 changes: 6 additions & 0 deletions test/syntax.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2268,3 +2268,9 @@ end
# issue #36196
@test_throws ParseError("\"for\" at none:1 expected \"end\", got \")\"") Meta.parse("(for i=1; println())")
@test_throws ParseError("\"try\" at none:1 expected \"end\", got \")\"") Meta.parse("(try i=1; println())")

# issue #36272
macro m36272()
:((a, b=1) -> a*b)
end
@test @m36272()(1) == 1

0 comments on commit 8d91b11

Please sign in to comment.