diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-06-29 04:01:30 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-06-29 04:01:30 +0000 |
commit | e7215d6278bb770c0a1656dae3b35a6ff4f28319 (patch) | |
tree | 131606bcfc545598f8c21ad5c4d046837f2e85d0 | |
parent | ff42412121f8d06e02410dd36552166c84b845f5 (diff) | |
download | ruby-e7215d6278bb770c0a1656dae3b35a6ff4f28319.tar.gz |
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]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59202 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | compile.c | 5 | ||||
-rw-r--r-- | test/ruby/test_exception.rb | 11 | ||||
-rw-r--r-- | test/ruby/test_syntax.rb | 8 |
3 files changed, 12 insertions, 12 deletions
@@ -29,6 +29,8 @@ #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_ANCHOR *const ret, NODE *node, int popp 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)); diff --git a/test/ruby/test_exception.rb b/test/ruby/test_exception.rb index ecbf042e49..6955118de7 100644 --- a/test/ruby/test_exception.rb +++ b/test/ruby/test_exception.rb @@ -1080,15 +1080,4 @@ $stderr = $stdout; raise "\x82\xa0"') do |outs, errs, status| } 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 diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb index b2bd688a77..c4d3d553be 100644 --- a/test/ruby/test_syntax.rb +++ b/test/ruby/test_syntax.rb @@ -478,8 +478,16 @@ WARN } 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 |