diff --git a/parse.y b/parse.y index 3d5ba3b1ea..1f000a13de 100644 --- a/parse.y +++ b/parse.y @@ -5995,9 +5995,7 @@ parser_yyerror(struct parser_params *p, const YYLTYPE *yylloc, const char *msg) yylloc = RUBY_SET_YYLLOC(current); } else if ((p->ruby_sourceline != yylloc->beg_pos.lineno && - p->ruby_sourceline != yylloc->end_pos.lineno) || - (yylloc->beg_pos.lineno == yylloc->end_pos.lineno && - yylloc->beg_pos.column == yylloc->end_pos.column)) { + p->ruby_sourceline != yylloc->end_pos.lineno)) { yylloc = 0; } compile_error(p, "%s", msg); diff --git a/test/ruby/test_parse.rb b/test/ruby/test_parse.rb index 625b6eb223..a9e8417357 100644 --- a/test/ruby/test_parse.rb +++ b/test/ruby/test_parse.rb @@ -1162,6 +1162,10 @@ x = __ENCODING__ assert_syntax_error("def m\n\C-z""end", /unexpected/) end + def test_unexpected_eof + assert_syntax_error('unless', /^ \^\Z/) + end + def test_location_of_invalid_token assert_syntax_error('class xxx end', /^ \^~~\Z/) end