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

ruby-changes:55870

From: Nobuyoshi <ko1@a...>
Date: Tue, 28 May 2019 09:04:10 +0900 (JST)
Subject: [ruby-changes:55870] Nobuyoshi Nakada: 1cdaa17a06 (trunk): parse.y: numbered parameter symbol

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

From 1cdaa17a065c529354fa9bcb4a1f3001783900ef Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Tue, 28 May 2019 08:44:28 +0900
Subject: parse.y: numbered parameter symbol

* parse.y (parse_atmark): numbered parameter name is not allowed
  as a symbol regardless the context.

diff --git a/parse.y b/parse.y
index 580b3c7..8a8c2ad 100644
--- a/parse.y
+++ b/parse.y
@@ -8375,7 +8375,10 @@ parse_atmark(struct parser_params *p, const enum lex_state_e last_state) https://github.com/ruby/ruby/blob/trunk/parse.y#L8375
 	    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 e21f1f9..11a77ba 100644
--- a/test/ruby/test_parse.rb
+++ b/test/ruby/test_parse.rb
@@ -590,6 +590,11 @@ class TestParse < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_parse.rb#L590
       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
-- 
cgit v0.10.2


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

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