Skip to content

Commit b210c86

Browse files
committed
merge revision(s) 9744933: [Backport #20649]
[Bug #20649] Allow `nil` as 2nd argument of `assign_error` Fallback to the last token element in that case, for the backward compatibilities.
1 parent 6a4e795 commit b210c86

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

ext/ripper/lib/ripper/lexer.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,12 @@ def on_error1(mesg)
242242
end
243243

244244
def on_error2(mesg, elem)
245-
@errors.push Elem.new(elem.pos, __callee__, elem.tok, elem.state, mesg)
245+
if elem
246+
elem = Elem.new(elem.pos, __callee__, elem.tok, elem.state, mesg)
247+
else
248+
elem = Elem.new([lineno(), column()], __callee__, token(), state(), mesg)
249+
end
250+
@errors.push elem
246251
end
247252
PARSER_EVENTS.grep(/_error\z/) do |e|
248253
arity = PARSER_EVENT_TABLE.fetch(e)

test/ripper/test_scanner_events.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ def test_tokenize
5353
Ripper.tokenize("1 .foo\n")
5454
assert_equal ["1", "\n", " ", ".", "foo", "\n"],
5555
Ripper.tokenize("1\n .foo\n")
56+
assert_equal ["def", " ", "f", ";", " ", "(", "x", ")", "::", "A", " ", "="],
57+
Ripper.tokenize("def f; (x)::A =")
5658
end
5759

5860
def test_lex

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
1212
#define RUBY_VERSION_TEENY 4
1313
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
14-
#define RUBY_PATCHLEVEL 96
14+
#define RUBY_PATCHLEVEL 97
1515

1616
#include "ruby/version.h"
1717
#include "ruby/internal/abi.h"

0 commit comments

Comments
 (0)