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

ruby-changes:65771

From: usa <ko1@a...>
Date: Mon, 5 Apr 2021 08:44:06 +0900 (JST)
Subject: [ruby-changes:65771] fd734d4992 (ruby_2_6): merge revision(s) 0036648a420f945624898568bb82bc5f83195d12: [Backport #17533]

https://git.ruby-lang.org/ruby.git/commit/?id=fd734d4992

From fd734d4992f68fb6d2e97e65cf97f6629e13a108 Mon Sep 17 00:00:00 2001
From: usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>
Date: Sun, 4 Apr 2021 23:43:53 +0000
Subject: merge revision(s) 0036648a420f945624898568bb82bc5f83195d12: [Backport
 #17533]

	Capture to reserved name variables if already defined [Bug #17533]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_6@67927 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
---
 parse.y                  |  5 +++--
 test/ruby/test_regexp.rb | 11 +++++++++++
 version.h                |  2 +-
 3 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/parse.y b/parse.y
index b073873..2b5a692 100644
--- a/parse.y
+++ b/parse.y
@@ -10684,12 +10684,13 @@ reg_named_capture_assign_iter(const OnigUChar *name, const OnigUChar *name_end, https://github.com/ruby/ruby/blob/trunk/parse.y#L10684
     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<<ID_LOCAL)) != ID_LOCAL)
         return ST_CONTINUE;
 
     var = intern_cstr(s, len, enc);
+    if (len < MAX_WORD_LENGTH && rb_reserved_word(s, (int)len)) {
+	if (!lvar_defined(p, var)) return ST_CONTINUE;
+    }
     node = node_assign(p, assignable(p, var, 0, arg->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 38147c7..038c1c8 100644
--- a/test/ruby/test_regexp.rb
+++ b/test/ruby/test_regexp.rb
@@ -218,6 +218,17 @@ class TestRegexp < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_regexp.rb#L218
   def test_assign_named_capture_to_reserved_word
     /(?<nil>.)/ =~ "a"
     assert_not_include(local_variables, :nil, "[ruby-dev:32675]")
+
+    def (obj = Object.new).test(s, nil: :ng)
+      /(?<nil>.)/ =~ s
+      binding.local_variable_get(:nil)
+    end
+    assert_equal("b", obj.test("b"))
+
+    tap do |nil: :ng|
+      /(?<nil>.)/ =~ "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 ca6cbc6..5fc9f34 100644
--- a/version.h
+++ b/version.h
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/version.h#L1
 #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
-- 
cgit v1.1


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

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