зеркало из https://github.com/github/ruby.git
Capture to reserved name variables if already defined [Bug #17533]
This commit is contained in:
Родитель
e9b93d67ba
Коммит
0036648a42
5
parse.y
5
parse.y
|
@ -12811,12 +12811,13 @@ reg_named_capture_assign_iter(const OnigUChar *name, const OnigUChar *name_end,
|
||||||
NODE *node, *succ;
|
NODE *node, *succ;
|
||||||
|
|
||||||
if (!len) return ST_CONTINUE;
|
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)
|
if (rb_enc_symname_type(s, len, enc, (1U<<ID_LOCAL)) != ID_LOCAL)
|
||||||
return ST_CONTINUE;
|
return ST_CONTINUE;
|
||||||
|
|
||||||
var = intern_cstr(s, len, enc);
|
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), NO_LEX_CTXT, arg->loc);
|
node = node_assign(p, assignable(p, var, 0, arg->loc), NEW_LIT(ID2SYM(var), arg->loc), NO_LEX_CTXT, arg->loc);
|
||||||
succ = arg->succ_block;
|
succ = arg->succ_block;
|
||||||
if (!succ) succ = NEW_BEGIN(0, arg->loc);
|
if (!succ) succ = NEW_BEGIN(0, arg->loc);
|
||||||
|
|
|
@ -229,6 +229,17 @@ class TestRegexp < Test::Unit::TestCase
|
||||||
def test_assign_named_capture_to_reserved_word
|
def test_assign_named_capture_to_reserved_word
|
||||||
/(?<nil>.)/ =~ "a"
|
/(?<nil>.)/ =~ "a"
|
||||||
assert_not_include(local_variables, :nil, "[ruby-dev:32675]")
|
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
|
end
|
||||||
|
|
||||||
def test_assign_named_capture_to_const
|
def test_assign_named_capture_to_const
|
||||||
|
|
Загрузка…
Ссылка в новой задаче