From 262b51744398ab650e956463b3bdf151fd7be4ac Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Wed, 10 May 2017 15:36:17 -0400 Subject: [PATCH] give a syntax error for repeated keyword args. fixes #16937 --- NEWS.md | 2 ++ src/julia-syntax.scm | 5 +++++ test/parse.jl | 4 ++++ 3 files changed, 11 insertions(+) diff --git a/NEWS.md b/NEWS.md index 27dc6ad493e44..a06c288206f9c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 -------------------- diff --git a/src/julia-syntax.scm b/src/julia-syntax.scm index 842327fe740d7..ac378d93a5a14 100644 --- a/src/julia-syntax.scm +++ b/src/julia-syntax.scm @@ -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))) diff --git a/test/parse.jl b/test/parse.jl index df2f38cfbd36f..9580927538289 100644 --- a/test/parse.jl +++ b/test/parse.jl @@ -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\"")