Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #41416, splatted default argument lost with keyword argument #41427

Merged
merged 1 commit into from
Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,))