Show the source line at an invalid class/instance variable
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67264 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
bf4bcaf061
commit
3134b20a01
7
parse.y
7
parse.y
@ -7586,9 +7586,12 @@ parse_gvar(struct parser_params *p, const enum lex_state_e last_state)
|
|||||||
static enum yytokentype
|
static enum yytokentype
|
||||||
parse_atmark(struct parser_params *p, const enum lex_state_e last_state)
|
parse_atmark(struct parser_params *p, const enum lex_state_e last_state)
|
||||||
{
|
{
|
||||||
|
const char *ptr = p->lex.pcur;
|
||||||
enum yytokentype result = tIVAR;
|
enum yytokentype result = tIVAR;
|
||||||
register int c = nextc(p);
|
register int c = nextc(p);
|
||||||
|
YYLTYPE loc;
|
||||||
|
|
||||||
|
p->lex.ptok = ptr - 1; /* from '@' */
|
||||||
newtok(p);
|
newtok(p);
|
||||||
tokadd(p, '@');
|
tokadd(p, '@');
|
||||||
if (c == '@') {
|
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)) {
|
if (c == -1 || !parser_is_identchar(p)) {
|
||||||
pushback(p, c);
|
pushback(p, c);
|
||||||
|
RUBY_SET_YYLLOC(loc);
|
||||||
if (result == tIVAR) {
|
if (result == tIVAR) {
|
||||||
compile_error(p, "`@' without identifiers is not allowed as an instance variable name");
|
compile_error(p, "`@' without identifiers is not allowed as an instance variable name");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
compile_error(p, "`@@' without identifiers is not allowed as a class variable name");
|
compile_error(p, "`@@' without identifiers is not allowed as a class variable name");
|
||||||
}
|
}
|
||||||
|
parser_show_error_line(p, &loc);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else if (ISDIGIT(c)) {
|
else if (ISDIGIT(c)) {
|
||||||
|
RUBY_SET_YYLLOC(loc);
|
||||||
pushback(p, c);
|
pushback(p, c);
|
||||||
if (result == tIVAR) {
|
if (result == tIVAR) {
|
||||||
compile_error(p, "`@%c' is not allowed as an instance variable name", c);
|
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 {
|
else {
|
||||||
compile_error(p, "`@@%c' is not allowed as a class variable name", c);
|
compile_error(p, "`@@%c' is not allowed as a class variable name", c);
|
||||||
}
|
}
|
||||||
|
parser_show_error_line(p, &loc);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,7 +246,7 @@ class TestISeq < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
assert_equal([m1, e1.message], [m2, e2.message], feature11951)
|
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([e1, :start_with?, __FILE__])
|
||||||
assert_send([e2, :start_with?, __FILE__])
|
assert_send([e2, :start_with?, __FILE__])
|
||||||
end
|
end
|
||||||
|
@ -720,13 +720,15 @@ x = __ENCODING__
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_invalid_instance_variable
|
def test_invalid_instance_variable
|
||||||
assert_raise(SyntaxError) { eval('@#') }
|
pattern = /without identifiers is not allowed as an instance variable name/
|
||||||
assert_raise(SyntaxError) { eval('@') }
|
assert_raise_with_message(SyntaxError, pattern) { eval('@%') }
|
||||||
|
assert_raise_with_message(SyntaxError, pattern) { eval('@') }
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_invalid_class_variable
|
def test_invalid_class_variable
|
||||||
assert_raise(SyntaxError) { eval('@@1') }
|
pattern = /without identifiers is not allowed as a class variable name/
|
||||||
assert_raise(SyntaxError) { eval('@@') }
|
assert_raise_with_message(SyntaxError, pattern) { eval('@@%') }
|
||||||
|
assert_raise_with_message(SyntaxError, pattern) { eval('@@') }
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_invalid_char
|
def test_invalid_char
|
||||||
|
Loading…
x
Reference in New Issue
Block a user