ruby-changes:55057
From: nobu <ko1@a...>
Date: Fri, 15 Mar 2019 09:45:00 +0900 (JST)
Subject: [ruby-changes:55057] nobu:r67264 (trunk): Show the source line at an invalid class/instance variable
nobu 2019-03-15 09:44:51 +0900 (Fri, 15 Mar 2019) New Revision: 67264 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=67264 Log: Show the source line at an invalid class/instance variable Modified files: trunk/parse.y trunk/test/ruby/test_iseq.rb trunk/test/ruby/test_parse.rb Index: test/ruby/test_iseq.rb =================================================================== --- test/ruby/test_iseq.rb (revision 67263) +++ test/ruby/test_iseq.rb (revision 67264) @@ -246,7 +246,7 @@ class TestISeq < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_iseq.rb#L246 end end assert_equal([m1, e1.message], [m2, e2.message], feature11951) - e1, e2 = e1.message.lines + e1, *, e2 = e1.message.lines assert_send([e1, :start_with?, __FILE__]) assert_send([e2, :start_with?, __FILE__]) end Index: test/ruby/test_parse.rb =================================================================== --- test/ruby/test_parse.rb (revision 67263) +++ test/ruby/test_parse.rb (revision 67264) @@ -720,13 +720,15 @@ x = __ENCODING__ https://github.com/ruby/ruby/blob/trunk/test/ruby/test_parse.rb#L720 end def test_invalid_instance_variable - assert_raise(SyntaxError) { eval('@#') } - assert_raise(SyntaxError) { eval('@') } + pattern = /without identifiers is not allowed as an instance variable name/ + assert_raise_with_message(SyntaxError, pattern) { eval('@%') } + assert_raise_with_message(SyntaxError, pattern) { eval('@') } end def test_invalid_class_variable - assert_raise(SyntaxError) { eval('@@1') } - assert_raise(SyntaxError) { eval('@@') } + pattern = /without identifiers is not allowed as a class variable name/ + assert_raise_with_message(SyntaxError, pattern) { eval('@@%') } + assert_raise_with_message(SyntaxError, pattern) { eval('@@') } end def test_invalid_char Index: parse.y =================================================================== --- parse.y (revision 67263) +++ parse.y (revision 67264) @@ -7586,9 +7586,12 @@ parse_gvar(struct parser_params *p, cons https://github.com/ruby/ruby/blob/trunk/parse.y#L7586 static enum yytokentype parse_atmark(struct parser_params *p, const enum lex_state_e last_state) { + const char *ptr = p->lex.pcur; enum yytokentype result = tIVAR; register int c = nextc(p); + YYLTYPE loc; + p->lex.ptok = ptr - 1; /* from '@' */ newtok(p); tokadd(p, '@'); if (c == '@') { @@ -7598,15 +7601,18 @@ parse_atmark(struct parser_params *p, co https://github.com/ruby/ruby/blob/trunk/parse.y#L7601 } if (c == -1 || !parser_is_identchar(p)) { pushback(p, c); + RUBY_SET_YYLLOC(loc); if (result == tIVAR) { compile_error(p, "`@' without identifiers is not allowed as an instance variable name"); } else { compile_error(p, "`@@' without identifiers is not allowed as a class variable name"); } + parser_show_error_line(p, &loc); return 0; } else if (ISDIGIT(c)) { + RUBY_SET_YYLLOC(loc); pushback(p, c); if (result == tIVAR) { compile_error(p, "`@%c' is not allowed as an instance variable name", c); @@ -7614,6 +7620,7 @@ parse_atmark(struct parser_params *p, co https://github.com/ruby/ruby/blob/trunk/parse.y#L7620 else { compile_error(p, "`@@%c' is not allowed as a class variable name", c); } + parser_show_error_line(p, &loc); return 0; } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/