Skip to content

Commit

Permalink
handle kwarg lowering for vararg with default value (#40977)
Browse files Browse the repository at this point in the history
Fixes #40964

(cherry picked from commit 8402463)
  • Loading branch information
JeffBezanson authored and staticfloat committed Dec 22, 2022
1 parent 2b59288 commit 8129887
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,9 @@
(body (blockify body))
(ftype (decl-type (car pargl)))
;; 1-element list of vararg argument, or empty if none
(vararg (let ((l (if (null? pargl) '() (last pargl))))
(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))
(list l) '())))
;; positional args with vararg
Expand Down
6 changes: 6 additions & 0 deletions test/keywordargs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -374,3 +374,9 @@ using InteractiveUtils
no_kw_args(x::Int) = 0
@test_throws MethodError no_kw_args(1, k=1)
@test_throws MethodError no_kw_args("", k=1)

# issue #40964
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)

0 comments on commit 8129887

Please sign in to comment.