Skip to content

Commit 262b517

Browse files
committed
give a syntax error for repeated keyword args. fixes #16937
1 parent 8f9a948 commit 262b517

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

NEWS.md

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ This section lists changes that do not have deprecation warnings.
2020
* `@__DIR__` returns the current working directory rather than `nothing` when not run
2121
from a file ([#21759]).
2222

23+
* Passing the same keyword argument multiple times is now a syntax error ([#16937]).
24+
2325

2426
Library improvements
2527
--------------------

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
@@ -1187,3 +1187,7 @@ module Test21607
11871187
x
11881188
end === 1.0
11891189
end
1190+
1191+
# issue #16937
1192+
@test expand(:(f(2, a=1, w=3, c=3, w=4, b=2))) == Expr(:error,
1193+
"keyword argument \"w\" repeated in call to \"f\"")

0 commit comments

Comments
 (0)