[前][次][番号順一覧][スレッド一覧]

ruby-changes:43778

From: nobu <ko1@a...>
Date: Wed, 10 Aug 2016 17:26:50 +0900 (JST)
Subject: [ruby-changes:43778] nobu:r55851 (trunk): parse.y: rescue modifier in rhs

nobu	2016-08-10 17:26:46 +0900 (Wed, 10 Aug 2016)

  New Revision: 55851

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55851

  Log:
    parse.y: rescue modifier in rhs
    
    * parse.y (command_asgn): rescue modifier in command assignment
      should be limited to rhs only.  [ruby-core:75621] [Bug #12402]

  Modified files:
    trunk/ChangeLog
    trunk/parse.y
    trunk/test/ruby/test_parse.rb
Index: parse.y
===================================================================
--- parse.y	(revision 55850)
+++ parse.y	(revision 55851)
@@ -1357,6 +1357,18 @@ command_asgn	: lhs '=' command_call https://github.com/ruby/ruby/blob/trunk/parse.y#L1357
 			$$ = dispatch2(assign, $1, $3);
 		    %*/
 		    }
+		| lhs '=' command_call modifier_rescue stmt
+		    {
+		    /*%%%*/
+			NODE *resq = NEW_RESBODY(0, remove_begin($5), 0);
+			value_expr($3);
+			resq = NEW_RESCUE($3, resq, 0);
+			$$ = node_assign($1, resq);
+		    /*%
+			$3 = dispatch2(rescue_mod, $3, $5);
+			$$ = dispatch2(assign, $1, $3);
+		    %*/
+		    }
 		| lhs '=' command_asgn
 		    {
 		    /*%%%*/
Index: test/ruby/test_parse.rb
===================================================================
--- test/ruby/test_parse.rb	(revision 55850)
+++ test/ruby/test_parse.rb	(revision 55851)
@@ -874,6 +874,16 @@ x = __ENCODING__ https://github.com/ruby/ruby/blob/trunk/test/ruby/test_parse.rb#L874
     assert_warning('') {eval("#{a} = 1; /(?<#{a}>)/ =~ ''")}
   end
 
+  def test_rescue_in_command_assignment
+    bug = '[ruby-core:75621] [Bug #12402]'
+    v = bug
+    v = raise(v) rescue "ok"
+    assert_equal("ok", v)
+    v = bug
+    v = raise v rescue "ok"
+    assert_equal("ok", v)
+  end
+
 =begin
   def test_past_scope_variable
     assert_warning(/past scope/) {catch {|tag| eval("BEGIN{throw tag}; tap {a = 1}; a")}}
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 55850)
+++ ChangeLog	(revision 55851)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Aug 10 17:26:43 2016  Nobuyoshi Nakada  <nobu@r...>
+
+	* parse.y (command_asgn): rescue modifier in command assignment
+	  should be limited to rhs only.  [ruby-core:75621] [Bug #12402]
+
 Wed Aug 10 15:35:03 2016  Nobuyoshi Nakada  <nobu@r...>
 
 	* ext/win32/resolv/resolv.c: needs windows.h for iphlpapi.h on

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]