diff --git a/lib/prism/translation/parser/lexer.rb b/lib/prism/translation/parser/lexer.rb index 6d3321b945d965..5c993cfab8167a 100644 --- a/lib/prism/translation/parser/lexer.rb +++ b/lib/prism/translation/parser/lexer.rb @@ -289,7 +289,7 @@ def to_a index += 1 end when :tFID - if tokens[-1][0] == :kDEF + if !tokens.empty? && tokens[-1][0] == :kDEF type = :tIDENTIFIER end end diff --git a/test/prism/fixtures/single_method_call_with_bang.txt b/test/prism/fixtures/single_method_call_with_bang.txt new file mode 100644 index 00000000000000..929efb30534598 --- /dev/null +++ b/test/prism/fixtures/single_method_call_with_bang.txt @@ -0,0 +1 @@ +foo! diff --git a/test/prism/snapshots/single_method_call_with_bang.txt b/test/prism/snapshots/single_method_call_with_bang.txt new file mode 100644 index 00000000000000..4c68e0adac9e4c --- /dev/null +++ b/test/prism/snapshots/single_method_call_with_bang.txt @@ -0,0 +1,15 @@ +@ ProgramNode (location: (1,0)-(1,4)) +├── locals: [] +└── statements: + @ StatementsNode (location: (1,0)-(1,4)) + └── body: (length: 1) + └── @ CallNode (location: (1,0)-(1,4)) + ├── flags: ignore_visibility + ├── receiver: ∅ + ├── call_operator_loc: ∅ + ├── name: :foo! + ├── message_loc: (1,0)-(1,4) = "foo!" + ├── opening_loc: ∅ + ├── arguments: ∅ + ├── closing_loc: ∅ + └── block: ∅