Skip to content

Commit

Permalink
give a syntax error for repeated keyword args. fixes #16937
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed May 16, 2017
1 parent 8f9a948 commit 262b517
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ This section lists changes that do not have deprecation warnings.
* `@__DIR__` returns the current working directory rather than `nothing` when not run
from a file ([#21759]).

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


Library improvements
--------------------
Expand Down
5 changes: 5 additions & 0 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -1439,6 +1439,11 @@
;; lower function call containing keyword arguments
(define (lower-kw-call fexpr kw0 pa)

;; check for keyword arguments syntactically passed more than once
(let ((dups (has-dups (map cadr (filter kwarg? kw0)))))
(if dups
(error (string "keyword argument \"" (car dups) "\" repeated in call to \"" (deparse fexpr) "\""))))

(define (kwcall-unless-empty f pa kw-container-test kw-container)
(let* ((expr_stmts (remove-argument-side-effects `(call ,f ,@pa)))
(pa (cddr (car expr_stmts)))
Expand Down
4 changes: 4 additions & 0 deletions test/parse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1187,3 +1187,7 @@ module Test21607
x
end === 1.0
end

# issue #16937
@test expand(:(f(2, a=1, w=3, c=3, w=4, b=2))) == Expr(:error,
"keyword argument \"w\" repeated in call to \"f\"")

0 comments on commit 262b517

Please sign in to comment.