aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-04-13 05:36:26 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-04-13 05:36:26 +0000
commit134d1ce89255f94c42730c814dbf3efed1c557d2 (patch)
tree15ea442be48eecefdb8a9b3c282c9af9422d0568
parent1ea1d2e4a7911f5c43fdea2daadc2ea9201d4a4d (diff)
downloadruby-134d1ce89255f94c42730c814dbf3efed1c557d2.tar.gz
parse.y: massign in cond
* parse.y (assign_in_cond): allow multiple assignment in conditional expression. [Feature #10617] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54558 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--NEWS3
-rw-r--r--parse.y3
-rw-r--r--test/ruby/test_assignment.rb5
-rw-r--r--test/ruby/test_parse.rb2
5 files changed, 14 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 197599d05c..f704ffef55 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Wed Apr 13 14:36:24 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * parse.y (assign_in_cond): allow multiple assignment in
+ conditional expression. [Feature #10617]
+
Wed Apr 13 14:11:59 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
* bignum.c (rb_big_size): add wrapper function of BIGSIZE and
diff --git a/NEWS b/NEWS
index 0f08b3daf2..858d6a0a2e 100644
--- a/NEWS
+++ b/NEWS
@@ -14,6 +14,9 @@ with all sufficient information, see the ChangeLog file or Redmine
=== Language changes
+* Multiple assignment in conditional expression is now allowed.
+ [Feature #10617]
+
=== Core classes updates (outstanding ones only)
* Array
diff --git a/parse.y b/parse.y
index 1bc22071b5..b8b4a21fa6 100644
--- a/parse.y
+++ b/parse.y
@@ -9785,9 +9785,6 @@ assign_in_cond(struct parser_params *parser, NODE *node)
{
switch (nd_type(node)) {
case NODE_MASGN:
- yyerror("multiple assignment in conditional");
- return 1;
-
case NODE_LASGN:
case NODE_DASGN:
case NODE_DASGN_CURR:
diff --git a/test/ruby/test_assignment.rb b/test/ruby/test_assignment.rb
index daf1f0a9be..41c14d3a44 100644
--- a/test/ruby/test_assignment.rb
+++ b/test/ruby/test_assignment.rb
@@ -552,6 +552,11 @@ class TestAssignment < Test::Unit::TestCase
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'
diff --git a/test/ruby/test_parse.rb b/test/ruby/test_parse.rb
index 42df89189c..9f83598ceb 100644
--- a/test/ruby/test_parse.rb
+++ b/test/ruby/test_parse.rb
@@ -781,7 +781,7 @@ x = __ENCODING__
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