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

ruby-changes:47087

From: nobu <ko1@a...>
Date: Thu, 29 Jun 2017 13:01:37 +0900 (JST)
Subject: [ruby-changes:47087] nobu:r59202 (trunk): compile.c: disallow next in once

nobu	2017-06-29 13:01:30 +0900 (Thu, 29 Jun 2017)

  New Revision: 59202

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

  Log:
    compile.c: disallow next in once
    
    * compile.c (iseq_compile_each0): turned dregx context in "once"
      into "guarded" type from "block" type, to disallow `next`,
      `break`, `redo` as well as outside "once".
      [ruby-core:81805] [Bug #13690]

  Modified files:
    trunk/compile.c
    trunk/test/ruby/test_exception.rb
    trunk/test/ruby/test_syntax.rb
Index: compile.c
===================================================================
--- compile.c	(revision 59201)
+++ compile.c	(revision 59202)
@@ -29,6 +29,8 @@ https://github.com/ruby/ruby/blob/trunk/compile.c#L29
 #undef RUBY_UNTYPED_DATA_WARNING
 #define RUBY_UNTYPED_DATA_WARNING 0
 
+#define ISEQ_TYPE_ONCE_GUARD ISEQ_TYPE_DEFINED_GUARD
+
 #define FIXNUM_INC(n, i) ((n)+(INT2FIX(i)&~FIXNUM_FLAG))
 #define FIXNUM_OR(n, i) ((n)|INT2FIX(i))
 
@@ -5966,7 +5968,8 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK https://github.com/ruby/ruby/blob/trunk/compile.c#L5968
 	int ic_index = iseq->body->is_size++;
 	NODE *dregx_node = NEW_NODE(NODE_DREGX, node->u1.value, node->u2.value, node->u3.value);
 	NODE *block_node = NEW_NODE(NODE_SCOPE, 0, dregx_node, 0);
-	const rb_iseq_t * block_iseq = NEW_CHILD_ISEQ(block_node, make_name_for_block(iseq), ISEQ_TYPE_BLOCK, line);
+	const rb_iseq_t *block_iseq = NEW_CHILD_ISEQ(block_node, make_name_for_block(iseq),
+						     ISEQ_TYPE_ONCE_GUARD, line);
 
 	ADD_INSN2(ret, line, once, block_iseq, INT2FIX(ic_index));
 
Index: test/ruby/test_exception.rb
===================================================================
--- test/ruby/test_exception.rb	(revision 59201)
+++ test/ruby/test_exception.rb	(revision 59202)
@@ -1080,15 +1080,4 @@ $stderr = $stdout; raise "\x82\xa0"') do https://github.com/ruby/ruby/blob/trunk/test/ruby/test_exception.rb#L1080
       }
     end;
   end
-
-  def test_break_in_once
-    assert_separately([], "#{<<-"begin;"}\n#{<<~'end;'}")
-    begin;
-      obj = Object.new
-      def obj.try
-        /#{break}/o
-      end
-      assert_raise(LocalJumpError, /proc-closure/) {obj.try}
-    end;
-  end
 end
Index: test/ruby/test_syntax.rb
===================================================================
--- test/ruby/test_syntax.rb	(revision 59201)
+++ test/ruby/test_syntax.rb	(revision 59202)
@@ -478,8 +478,16 @@ WARN https://github.com/ruby/ruby/blob/trunk/test/ruby/test_syntax.rb#L478
     }
   end
 
+  def test_invalid_break
+    assert_syntax_error("def m; break; end", /Invalid break/)
+    assert_syntax_error('/#{break}/', /Invalid break/)
+    assert_syntax_error('/#{break}/o', /Invalid break/)
+  end
+
   def test_invalid_next
     assert_syntax_error("def m; next; end", /Invalid next/)
+    assert_syntax_error('/#{next}/', /Invalid next/)
+    assert_syntax_error('/#{next}/o', /Invalid next/)
   end
 
   def test_lambda_with_space

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

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