ruby-changes:42484
From: nobu <ko1@a...>
Date: Wed, 13 Apr 2016 13:39:50 +0900 (JST)
Subject: [ruby-changes:42484] nobu:r54558 (trunk): parse.y: massign in cond
nobu 2016-04-13 14:36:26 +0900 (Wed, 13 Apr 2016) New Revision: 54558 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54558 Log: parse.y: massign in cond * parse.y (assign_in_cond): allow multiple assignment in conditional expression. [Feature #10617] Modified files: trunk/ChangeLog trunk/NEWS trunk/parse.y trunk/test/ruby/test_assignment.rb trunk/test/ruby/test_parse.rb Index: NEWS =================================================================== --- NEWS (revision 54557) +++ NEWS (revision 54558) @@ -14,6 +14,9 @@ with all sufficient information, see the https://github.com/ruby/ruby/blob/trunk/NEWS#L14 === Language changes +* Multiple assignment in conditional expression is now allowed. + [Feature #10617] + === Core classes updates (outstanding ones only) * Array Index: ChangeLog =================================================================== --- ChangeLog (revision 54557) +++ ChangeLog (revision 54558) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Wed Apr 13 14:36:24 2016 Nobuyoshi Nakada <nobu@r...> + + * parse.y (assign_in_cond): allow multiple assignment in + conditional expression. [Feature #10617] + Wed Apr 13 14:11:59 2016 Nobuyoshi Nakada <nobu@r...> * bignum.c (rb_big_size): add wrapper function of BIGSIZE and Index: test/ruby/test_assignment.rb =================================================================== --- test/ruby/test_assignment.rb (revision 54557) +++ test/ruby/test_assignment.rb (revision 54558) @@ -552,6 +552,11 @@ class TestAssignment < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/ruby/test_assignment.rb#L552 a, b = Base::A, Base::B assert_equal [3,4], [a,b] end + + def test_massign_in_cond + result = eval("if (a, b = MyObj.new); [a, b]; end", nil, __FILE__, __LINE__) + assert_equal [[1,2],[3,4]], result + end end require_relative 'sentence' Index: test/ruby/test_parse.rb =================================================================== --- test/ruby/test_parse.rb (revision 54557) +++ test/ruby/test_parse.rb (revision 54558) @@ -781,7 +781,7 @@ x = __ENCODING__ https://github.com/ruby/ruby/blob/trunk/test/ruby/test_parse.rb#L781 end def test_assign_in_conditional - assert_raise(SyntaxError) do + assert_nothing_raised do eval <<-END, nil, __FILE__, __LINE__+1 (x, y = 1, 2) ? 1 : 2 END Index: parse.y =================================================================== --- parse.y (revision 54557) +++ parse.y (revision 54558) @@ -9785,9 +9785,6 @@ assign_in_cond(struct parser_params *par https://github.com/ruby/ruby/blob/trunk/parse.y#L9785 { switch (nd_type(node)) { case NODE_MASGN: - yyerror("multiple assignment in conditional"); - return 1; - case NODE_LASGN: case NODE_DASGN: case NODE_DASGN_CURR: -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/