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
This commit is contained in:
parent
8890779077
commit
fd734d4992
5
parse.y
5
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<<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);
|
||||
|
|
|
@ -218,6 +218,17 @@ class TestRegexp < Test::Unit::TestCase
|
|||
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
|
||||
|
|
Loading…
Reference in New Issue