ruby-changes:58105
From: Yusuke <ko1@a...>
Date: Fri, 4 Oct 2019 02:43:23 +0900 (JST)
Subject: [ruby-changes:58105] c3dd3b9553 (master): iseq.c (rb_iseq_compile_with_option): dummy parent_iseq for the parser
https://git.ruby-lang.org/ruby.git/commit/?id=c3dd3b9553 From c3dd3b95538a641bbffb02993985ce0cbac1b9d6 Mon Sep 17 00:00:00 2001 From: Yusuke Endoh <mame@r...> Date: Fri, 4 Oct 2019 02:35:10 +0900 Subject: iseq.c (rb_iseq_compile_with_option): dummy parent_iseq for the parser The parsing of `RubyVM::InstructionSequence.compile` does not support an outer scope currently. So it specified NULL as parent_iseq for the parser. However, it resulted in the following false-positive warning. ``` RubyVM::InstructionSequence.compile(<<END) o = Object.new o #=> <compiled>:2: warning: possibly useless use of a variable in void context END ``` This change specifies a dummy empty parent_iseq instead of NULL, which suppresses the false positive. diff --git a/iseq.c b/iseq.c index d7e8cce..fcf38fc 100644 --- a/iseq.c +++ b/iseq.c @@ -994,7 +994,14 @@ rb_iseq_compile_with_option(VALUE src, VALUE file, VALUE realpath, VALUE line, c https://github.com/ruby/ruby/blob/trunk/iseq.c#L994 } { const VALUE parser = rb_parser_new(); - rb_parser_set_context(parser, parent, FALSE); + const rb_iseq_t *outer_scope = parent; + if (!outer_scope) { + VALUE name = rb_fstring_lit("<compiled>"); + outer_scope = rb_iseq_new(NULL, name, name, Qnil, 0, ISEQ_TYPE_TOP); + } + VALUE outer_scope_v = (VALUE)outer_scope; + rb_parser_set_context(parser, outer_scope, FALSE); + RB_GC_GUARD(outer_scope_v); ast = (*parse)(parser, file, src, ln); } -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/