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

ruby-changes:44126

From: nobu <ko1@a...>
Date: Wed, 21 Sep 2016 13:47:41 +0900 (JST)
Subject: [ruby-changes:44126] nobu:r56199 (trunk): parse.y: preserve cmdarg_stack

nobu	2016-09-21 13:47:35 +0900 (Wed, 21 Sep 2016)

  New Revision: 56199

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

  Log:
    parse.y: preserve cmdarg_stack
    
    * parse.y (brace_body, do_body): preserve cmdarg_stack so that
      `do` after cmdarg in a block should be `do_block` and bound to
      the outer method.  [ruby-core:72482] [Bug #11873]

  Modified files:
    trunk/ChangeLog
    trunk/parse.y
    trunk/test/ruby/test_syntax.rb
Index: parse.y
===================================================================
--- parse.y	(revision 56198)
+++ parse.y	(revision 56199)
@@ -3759,13 +3759,23 @@ brace_block	: '{' https://github.com/ruby/ruby/blob/trunk/parse.y#L3759
 		;
 
 brace_body	: {$<vars>$ = dyna_push();}
+		  {$<val>$ = cmdarg_stack >> 1; CMDARG_SET(0);}
 		  opt_block_param compstmt
-		  {$$ = new_brace_body($2, $3); dyna_pop($<vars>1);}
+		    {
+			$$ = new_brace_body($3, $4);
+			dyna_pop($<vars>1);
+			CMDARG_SET($<num>2);
+		    }
 		;
 
 do_body 	: {$<vars>$ = dyna_push();}
+		  {$<val>$ = cmdarg_stack >> 1; CMDARG_SET(0);}
 		  opt_block_param compstmt
-		  {$$ = new_do_body($2, $3); dyna_pop($<vars>1);}
+		    {
+			$$ = new_do_body($3, $4);
+			dyna_pop($<vars>1);
+			CMDARG_SET($<num>2);
+		    }
 		;
 
 case_body	: keyword_when args then
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 56198)
+++ ChangeLog	(revision 56199)
@@ -1,10 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
-Wed Sep 21 13:38:44 2016  Nobuyoshi Nakada  <nobu@r...>
+Wed Sep 21 13:47:33 2016  Nobuyoshi Nakada  <nobu@r...>
+
+	* parse.y (brace_body, do_body): preserve cmdarg_stack so that
+	  `do` after cmdarg in a block should be `do_block` and bound to
+	  the outer method.  [ruby-core:72482] [Bug #11873]
 
 	* parse.y: `do` after cmdarg in parentheses should be `do_block`
 	  and bound to the outer method.  [ruby-core:72482] [Bug #11873]
 
-Wed Sep 21 13:32:00 2016  Nobuyoshi Nakada  <nobu@r...>
-
 	* parse.y (brace_body, do_body): extract block bodies.
 
 Tue Sep 20 23:02:50 2016  Nobuyoshi Nakada  <nobu@r...>
Index: test/ruby/test_syntax.rb
===================================================================
--- test/ruby/test_syntax.rb	(revision 56198)
+++ test/ruby/test_syntax.rb	(revision 56199)
@@ -840,6 +840,27 @@ eom https://github.com/ruby/ruby/blob/trunk/test/ruby/test_syntax.rb#L840
     assert_valid_syntax %q{a b(c(d)), :e do end}, bug11873
   end
 
+  def test_block_after_cmdarg_in_paren
+    bug11873 = '[ruby-core:72482] [Bug #11873]'
+    def bug11873.p(*);end;
+
+    assert_raise(LocalJumpError, bug11873) do
+      bug11873.instance_eval do
+        p p{p p;p(p)}, tap do
+          raise SyntaxError, "should not be passed to tap"
+        end
+      end
+    end
+
+    assert_raise(LocalJumpError, bug11873) do
+      bug11873.instance_eval do
+        p p{p(p);p p}, tap do
+          raise SyntaxError, "should not be passed to tap"
+        end
+      end
+    end
+  end
+
   private
 
   def not_label(x) @result = x; @not_label ||= nil end

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

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