Skip to content

Commit 6b0518f

Browse files
committed
give a syntax error for repeated keyword args. fixes #16937
1 parent 22d4d84 commit 6b0518f

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/julia-syntax.scm

+5
Original file line numberDiff line numberDiff line change
@@ -1439,6 +1439,11 @@
14391439
;; lower function call containing keyword arguments
14401440
(define (lower-kw-call fexpr kw0 pa)
14411441

1442+
;; check for keyword arguments syntactically passed more than once
1443+
(let ((dups (has-dups (map cadr (filter kwarg? kw0)))))
1444+
(if dups
1445+
(error (string "keyword argument \"" (car dups) "\" repeated in call to \"" (deparse fexpr) "\""))))
1446+
14421447
(define (kwcall-unless-empty f pa kw-container-test kw-container)
14431448
(let* ((expr_stmts (remove-argument-side-effects `(call ,f ,@pa)))
14441449
(pa (cddr (car expr_stmts)))

test/parse.jl

+4
Original file line numberDiff line numberDiff line change
@@ -1183,3 +1183,7 @@ module Test21607
11831183
x
11841184
end === 1.0
11851185
end
1186+
1187+
# issue #16937
1188+
@test expand(:(f(2, a=1, w=3, c=3, w=4, b=2))) == Expr(:error,
1189+
"keyword argument \"w\" repeated in call to \"f\"")

0 commit comments

Comments
 (0)