summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2021-10-05 16:44:43 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2021-10-05 16:44:43 +0900
commit1f544d671580dab465df56f42e142db4667f782e (patch)
tree2a89d6c51fe82f14846f82f1c1195b363a88d5ed
parent5a961c37682383d5d439a16b912be62cd2d0a7f0 (diff)
Show the last line at unexpected end-of-input error
-rw-r--r--parse.y4
-rw-r--r--test/ruby/test_parse.rb4
2 files changed, 5 insertions, 3 deletions
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