aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--parse.y7
-rw-r--r--test/ruby/test_iseq.rb2
-rw-r--r--test/ruby/test_parse.rb10
3 files changed, 14 insertions, 5 deletions
diff --git a/parse.y b/parse.y
index fd7ba924f9..b904797969 100644
--- a/parse.y
+++ b/parse.y
@@ -7586,9 +7586,12 @@ parse_gvar(struct parser_params *p, const enum lex_state_e last_state)
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, const enum lex_state_e last_state)
}
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, const enum lex_state_e last_state)
else {
compile_error(p, "`@@%c' is not allowed as a class variable name", c);
}
+ parser_show_error_line(p, &loc);
return 0;
}
diff --git a/test/ruby/test_iseq.rb b/test/ruby/test_iseq.rb
index cac159085a..f2d11cdb7e 100644
--- a/test/ruby/test_iseq.rb
+++ b/test/ruby/test_iseq.rb
@@ -246,7 +246,7 @@ class TestISeq < Test::Unit::TestCase
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
diff --git a/test/ruby/test_parse.rb b/test/ruby/test_parse.rb
index 0b3657f8a0..d21484f4b6 100644
--- a/test/ruby/test_parse.rb
+++ b/test/ruby/test_parse.rb
@@ -720,13 +720,15 @@ x = __ENCODING__
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