diff --git a/parse.y b/parse.y index b0738737cd..2b5a692558 100644 --- a/parse.y +++ b/parse.y @@ -10684,12 +10684,13 @@ reg_named_capture_assign_iter(const OnigUChar *name, const OnigUChar *name_end, NODE *node, *succ; if (!len) return ST_CONTINUE; - if (len < MAX_WORD_LENGTH && rb_reserved_word(s, (int)len)) - return ST_CONTINUE; if (rb_enc_symname_type(s, len, enc, (1U<loc), NEW_LIT(ID2SYM(var), arg->loc), arg->loc); succ = arg->succ_block; if (!succ) succ = NEW_BEGIN(0, arg->loc); diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb index 38147c7446..038c1c830f 100644 --- a/test/ruby/test_regexp.rb +++ b/test/ruby/test_regexp.rb @@ -218,6 +218,17 @@ class TestRegexp < Test::Unit::TestCase def test_assign_named_capture_to_reserved_word /(?.)/ =~ "a" assert_not_include(local_variables, :nil, "[ruby-dev:32675]") + + def (obj = Object.new).test(s, nil: :ng) + /(?.)/ =~ s + binding.local_variable_get(:nil) + end + assert_equal("b", obj.test("b")) + + tap do |nil: :ng| + /(?.)/ =~ "c" + assert_equal("c", binding.local_variable_get(:nil)) + end end def test_assign_named_capture_to_const diff --git a/version.h b/version.h index ca6cbc67d2..5fc9f34f8f 100644 --- a/version.h +++ b/version.h @@ -1,6 +1,6 @@ #define RUBY_VERSION "2.6.7" #define RUBY_RELEASE_DATE "2021-04-05" -#define RUBY_PATCHLEVEL 186 +#define RUBY_PATCHLEVEL 187 #define RUBY_RELEASE_YEAR 2021 #define RUBY_RELEASE_MONTH 4