From f296c260ef3b2d1a9299dbb4a84df567972453f2 Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Thu, 4 Jul 2019 13:47:43 -0700 Subject: Fix segfault when using method reference operator without using result Fixes [Bug #15985] --- compile.c | 5 ++++- test/ruby/test_syntax.rb | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/compile.c b/compile.c index 7550bb9b64..bf61a06c00 100644 --- a/compile.c +++ b/compile.c @@ -8146,8 +8146,11 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *node, in break; } case NODE_METHREF: - CHECK(COMPILE_(ret, "receiver", node->nd_recv, popped)); + CHECK(COMPILE(ret, "receiver", node->nd_recv)); ADD_ELEM(ret, &new_insn_body(iseq, line, BIN(methodref), 1, ID2SYM(node->nd_mid))->link); + if (popped) { + ADD_INSN(ret, line, pop); + } break; default: UNKNOWN_NODE("iseq_compile_each", node, COMPILE_NG); diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb index 7d99c233fd..18546efe63 100644 --- a/test/ruby/test_syntax.rb +++ b/test/ruby/test_syntax.rb @@ -93,6 +93,13 @@ class TestSyntax < Test::Unit::TestCase assert_valid_syntax("tap (proc do end)", __FILE__, bug9726) end + def test_methodref_literal + assert_separately [], <<-EOS + eval 'nil.:|;1' + 1000.times{eval 'nil.:|;1'} + EOS + end + def test_normal_argument assert_valid_syntax('def foo(x) end') assert_syntax_error('def foo(X) end', /constant/) -- cgit v1.2.3