Skip to content

Commit a0720ce

Browse files
committed
allow fully-evaluated keyword argument pairs. closes #7704
anything in an argument list after a ; that's not of the form `a=b` will be evaluated and expected to be some kind of pair of a symbol and value.
1 parent 8c60aac commit a0720ce

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

src/julia-syntax.scm

+13-7
Original file line numberDiff line numberDiff line change
@@ -1454,7 +1454,9 @@
14541454
"\" (expected assignment)"))))))))
14551455

14561456
(define (lower-kw-call f kw pa)
1457-
(check-kw-args kw)
1457+
(if (any (lambda (x) (and (pair? x) (eq? (car x) 'parameters)))
1458+
kw)
1459+
(error "more than one semicolon in argument list"))
14581460
(receive
14591461
(keys restkeys) (separate kwarg? kw)
14601462
(let ((keyargs (apply append
@@ -1476,12 +1478,16 @@
14761478
,@(let ((k (gensy))
14771479
(v (gensy)))
14781480
(map (lambda (rk)
1479-
`(for (= (tuple ,k ,v) ,(cadr rk))
1480-
(ccall 'jl_cell_1d_push2 Void
1481-
(tuple Any Any Any)
1482-
,container
1483-
(|::| ,k (top Symbol))
1484-
,v)))
1481+
(let ((push-expr `(ccall 'jl_cell_1d_push2 Void
1482+
(tuple Any Any Any)
1483+
,container
1484+
(|::| ,k (top Symbol))
1485+
,v)))
1486+
(if (vararg? rk)
1487+
`(for (= (tuple ,k ,v) ,(cadr rk))
1488+
,push-expr)
1489+
`(block (= (tuple ,k ,v) ,rk)
1490+
,push-expr))))
14851491
restkeys))
14861492
(if (call (top isempty) ,container)
14871493
(call ,f ,@pa)

test/keywordargs.jl

+9
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,12 @@ function test4974(;kwargs...)
174174
end
175175

176176
@test test4974(a=1) == (2, {(:a,1)})
177+
178+
# issue #7704, computed keywords
179+
@test kwf1(1; (:tens, 2)) == 21
180+
let
181+
p = (:hundreds, 3)
182+
q = (:tens, 1)
183+
@test kwf1(0; p, q) == 310
184+
@test kwf1(0; q, hundreds=4) == 410
185+
end

0 commit comments

Comments
 (0)