1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

parse.y: numbered parameter symbol

* parse.y (parse_atmark): numbered parameter name is not allowed
  as a symbol regardless the context.
This commit is contained in:
Nobuyoshi Nakada 2019-05-28 08:44:28 +09:00
parent 57b4df07bc
commit 1cdaa17a06
No known key found for this signature in database
GPG key ID: 4BC7D6DF58D8DF60
2 changed files with 9 additions and 1 deletions

View file

@ -8375,7 +8375,10 @@ parse_atmark(struct parser_params *p, const enum lex_state_e last_state)
unsigned long n = ruby_scan_digits(ptr, len, 10, &len, &overflow);
p->lex.pcur = ptr + len;
RUBY_SET_YYLLOC(loc);
if (ptr[0] == '0') {
if (IS_lex_state(EXPR_FNAME)) {
compile_error(p, "`@%c' is not allowed as an instance variable name", c);
}
else if (ptr[0] == '0') {
compile_error(p, "leading zero is not allowed as a numbered parameter");
}
else if (overflow || n > NUMPARAM_MAX) {

View file

@ -590,6 +590,11 @@ class TestParse < Test::Unit::TestCase
assert_equal(:foobar, eval(':"foo\u{}bar"'))
assert_equal(:foobar, eval(':"foo\u{ }bar"'))
end
assert_syntax_error(':@@', /is not allowed/)
assert_syntax_error(':@@1', /is not allowed/)
assert_syntax_error(':@', /is not allowed/)
assert_syntax_error(':@1', /is not allowed/)
end
def test_parse_string