summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNobuyoshi Nakada <[email protected]>2024-07-24 21:28:18 +0900
committerNobuyoshi Nakada <[email protected]>2024-07-24 22:18:36 +0900
commit97449338d6cb42d9dd7c9ca61550616e7e6b6ef6 (patch)
treed0d9f360916c3f303d416d84fcbe7ff138c4e85b
parentf69ba5716f17d8ebe089a4986977afd2feefabc2 (diff)
[Bug #20649] Allow `nil` as 2nd argument of `assign_error`
Fallback to the last token element in that case, for the backward compatibilities.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/11235
-rw-r--r--ext/ripper/lib/ripper/lexer.rb7
-rw-r--r--test/ripper/test_scanner_events.rb2
2 files changed, 8 insertions, 1 deletions
diff --git a/ext/ripper/lib/ripper/lexer.rb b/ext/ripper/lib/ripper/lexer.rb
index 6a3c04af30..a0f1cbeaa8 100644
--- a/ext/ripper/lib/ripper/lexer.rb
+++ b/ext/ripper/lib/ripper/lexer.rb
@@ -242,7 +242,12 @@ class Ripper
end
def on_error2(mesg, elem)
- @errors.push Elem.new(elem.pos, __callee__, elem.tok, elem.state, mesg)
+ if elem
+ elem = Elem.new(elem.pos, __callee__, elem.tok, elem.state, mesg)
+ else
+ elem = Elem.new([lineno(), column()], __callee__, token(), state(), mesg)
+ end
+ @errors.push elem
end
PARSER_EVENTS.grep(/_error\z/) do |e|
arity = PARSER_EVENT_TABLE.fetch(e)
diff --git a/test/ripper/test_scanner_events.rb b/test/ripper/test_scanner_events.rb
index 792f19ef1a..261e259889 100644
--- a/test/ripper/test_scanner_events.rb
+++ b/test/ripper/test_scanner_events.rb
@@ -53,6 +53,8 @@ class TestRipper::ScannerEvents < Test::Unit::TestCase
Ripper.tokenize("1 .foo\n")
assert_equal ["1", "\n", " ", ".", "foo", "\n"],
Ripper.tokenize("1\n .foo\n")
+ assert_equal ["def", " ", "f", ";", " ", "(", "x", ")", "::", "A", " ", "="],
+ Ripper.tokenize("def f; (x)::A =")
end
def test_lex