Skip to content

Commit

Permalink
fix JuliaLang#41416, splatted default argument lost with keyword argu…
Browse files Browse the repository at this point in the history
…ment (JuliaLang#41427)
  • Loading branch information
JeffBezanson authored and johanmon committed Jul 5, 2021
1 parent 9c9d23e commit d69177f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
6 changes: 5 additions & 1 deletion src/ast.scm
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@
(bad-formal-argument v))
(else
(case (car v)
((... kw)
((...)
(arg-name (cadr v)) ;; to check for errors
(decl-var (cadr v)))
((|::|)
Expand All @@ -330,6 +330,8 @@
(if (nospecialize-meta? v #t)
(arg-name (caddr v))
(bad-formal-argument v)))
((kw)
(arg-name (cadr v)))
(else (bad-formal-argument v))))))

(define (arg-type v)
Expand All @@ -349,6 +351,8 @@
(if (nospecialize-meta? v #t)
(arg-type (caddr v))
(bad-formal-argument v)))
((kw)
(arg-type (cadr v)))
(else (bad-formal-argument v))))))

;; convert a lambda list into a list of just symbols
Expand Down
17 changes: 8 additions & 9 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,12 @@
;; 1-element list of vararg argument, or empty if none
(vararg (let* ((l (if (null? pargl) '() (last pargl)))
;; handle vararg with default value
(l (if (kwarg? l) (cadr l) l)))
(if (or (vararg? l) (varargexpr? l))
(l- (if (kwarg? l) (cadr l) l)))
(if (or (vararg? l-) (varargexpr? l-))
(list l) '())))
;; expression to forward varargs to another call
(splatted-vararg (if (null? vararg) '()
(list `(... ,(arg-name (car vararg))))))
;; positional args with vararg
(pargl-all pargl)
;; positional args without vararg
Expand Down Expand Up @@ -520,8 +523,7 @@
,@(if ordered-defaults keynames vals)
,@(if (null? restkw) '() `((call (top pairs) (call (core NamedTuple)))))
,@(map arg-name pargl)
,@(if (null? vararg) '()
(list `(... ,(arg-name (car vararg)))))))))
,@splatted-vararg))))
(if ordered-defaults
(scopenest keynames vals ret)
ret))))
Expand Down Expand Up @@ -579,16 +581,13 @@
,@(if (null? restkw)
`((if (call (top isempty) ,rkw)
(null)
(call (top kwerr) ,kw ,@(map arg-name pargl)
,@(if (null? vararg) '()
(list `(... ,(arg-name (car vararg))))))))
(call (top kwerr) ,kw ,@(map arg-name pargl) ,@splatted-vararg)))
'())
(return (call ,mangled ;; finally, call the core function
,@keynames
,@(if (null? restkw) '() (list rkw))
,@(map arg-name pargl)
,@(if (null? vararg) '()
(list `(... ,(arg-name (car vararg)))))))))))
,@splatted-vararg))))))
;; return primary function
,(if (not (symbol? name))
'(null) name)))))
Expand Down
7 changes: 7 additions & 0 deletions test/keywordargs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -380,3 +380,10 @@ f40964(xs::Int...=1; k = 2) = (xs, k)
@test f40964() === ((1,), 2)
@test f40964(7, 8) === ((7,8), 2)
@test f40964(7, 8, k=0) === ((7,8), 0)
# issue #41416
@test f40964(; k = 1) === ((1,), 1)
f41416(a...="a"; b=true) = (b, a)
@test f41416() === (true, ("a",))
@test f41416(;b=false) === (false, ("a",))
@test f41416(33) === (true, (33,))
@test f41416(3; b=false) === (false, (3,))

0 comments on commit d69177f

Please sign in to comment.