From 01740f0c273c89f7bcff3d5014d73c8ff6fb1986 Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 5 Mar 2014 06:56:49 +0000 Subject: parse.y: optional arguments in rhs * parse.y (f_arg_asgn): define optional arguments as argument variables in the rhs default expressions. [ruby-core:61299] [Bug #9593] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45272 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_syntax.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'test/ruby') diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb index cac755a390..bc1d80f990 100644 --- a/test/ruby/test_syntax.rb +++ b/test/ruby/test_syntax.rb @@ -111,6 +111,30 @@ class TestSyntax < Test::Unit::TestCase assert_raise(TypeError) {o.kw(**h)} end + def test_keyword_self_reference + bug9593 = '[ruby-core:61299] [Bug #9593]' + o = Object.new + def o.foo(var: defined?(var)) var end + assert_equal(42, o.foo(var: 42)) + assert_equal("local-variable", o.foo, bug9593) + + o = Object.new + def o.foo(var: var) var end + assert_nil(o.foo, bug9593) + end + + def test_optional_self_reference + bug9593 = '[ruby-core:61299] [Bug #9593]' + o = Object.new + def o.foo(var = defined?(var)) var end + assert_equal(42, o.foo(42)) + assert_equal("local-variable", o.foo, bug9593) + + o = Object.new + def o.foo(var = var) var end + assert_nil(o.foo, bug9593) + end + def test_warn_grouped_expression bug5214 = '[ruby-core:39050]' assert_warning("", bug5214) do -- cgit v1.2.3