From 38da1a5398f146a36910fde34b72dc9b3aa7918f Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 7 Jan 2013 06:32:01 +0000 Subject: [PATCH] parse.y: duplicated kwrest name * parse.y (f_kwrest): reject duplicated kwrest argument name. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38724 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 ++++ parse.y | 1 + test/ruby/test_syntax.rb | 52 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+) diff --git a/ChangeLog b/ChangeLog index 624fc701ee..aed7245394 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Mon Jan 7 15:31:58 2013 Nobuyoshi Nakada + + * parse.y (f_kwrest): reject duplicated kwrest argument name. + Mon Jan 7 15:24:10 2013 Koichi Sasada * vm_trace.c (rb_threadptr_exec_event_hooks_orig): pop tag before diff --git a/parse.y b/parse.y index f9e832996e..56c9425a29 100644 --- a/parse.y +++ b/parse.y @@ -4682,6 +4682,7 @@ kwrest_mark : tPOW f_kwrest : kwrest_mark tIDENTIFIER { + shadowing_lvar(get_id($2)); $$ = $2; } ; diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb index 8c1d0715df..f2b42d8a3b 100644 --- a/test/ruby/test_syntax.rb +++ b/test/ruby/test_syntax.rb @@ -133,6 +133,58 @@ class TestSyntax < Test::Unit::TestCase assert_not_label(:foo, 'class Foo < not_label:foo; end', bug6347) end + def test_duplicated_arg + assert_syntax_error("def foo(a, a) end", /duplicated argument name/) + end + + def test_duplicated_rest + assert_syntax_error("def foo(a, *a) end", /duplicated argument name/) + end + + def test_duplicated_opt + assert_syntax_error("def foo(a, a=1) end", /duplicated argument name/) + end + + def test_duplicated_opt_rest + assert_syntax_error("def foo(a=1, *a) end", /duplicated argument name/) + end + + def test_duplicated_rest_opt + assert_syntax_error("def foo(*a, a=1) end", /duplicated argument name/) + end + + def test_duplicated_rest_post + assert_syntax_error("def foo(*a, a) end", /duplicated argument name/) + end + + def test_duplicated_opt_post + assert_syntax_error("def foo(a=1, a) end", /duplicated argument name/) + end + + def test_duplicated_kw + assert_syntax_error("def foo(a, a: 1) end", /duplicated argument name/) + end + + def test_duplicated_rest_kw + assert_syntax_error("def foo(*a, a: 1) end", /duplicated argument name/) + end + + def test_duplicated_opt_kw + assert_syntax_error("def foo(a=1, a: 1) end", /duplicated argument name/) + end + + def test_duplicated_kw_kwrest + assert_syntax_error("def foo(a: 1, **a) end", /duplicated argument name/) + end + + def test_duplicated_rest_kwrest + assert_syntax_error("def foo(*a, **a) end", /duplicated argument name/) + end + + def test_duplicated_opt_kwrest + assert_syntax_error("def foo(a=1, **a) end", /duplicated argument name/) + end + def test_duplicated_when w = 'warning: duplicated when clause is ignored' assert_warning(/3: #{w}.+4: #{w}.+4: #{w}.+5: #{w}.+5: #{w}/m){