aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2019-05-28 08:44:28 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2019-05-28 09:00:02 +0900
commit1cdaa17a065c529354fa9bcb4a1f3001783900ef (patch)
treee2edd2ebf20a19f9b20f9ce94d7516ddf5e0399a
parent57b4df07bc1e863c48a3b0f4c3185de431454695 (diff)
downloadruby-1cdaa17a065c529354fa9bcb4a1f3001783900ef.tar.gz
parse.y: numbered parameter symbol
* parse.y (parse_atmark): numbered parameter name is not allowed as a symbol regardless the context.
-rw-r--r--parse.y5
-rw-r--r--test/ruby/test_parse.rb5
2 files changed, 9 insertions, 1 deletions
diff --git a/parse.y b/parse.y
index 580b3c72da..8a8c2adc09 100644
--- a/parse.y
+++ b/parse.y
@@ -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) {
diff --git a/test/ruby/test_parse.rb b/test/ruby/test_parse.rb
index e21f1f9515..11a77bacd8 100644
--- a/test/ruby/test_parse.rb
+++ b/test/ruby/test_parse.rb
@@ -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