Skip to content

Fix off-by-one line number in parse error messages#1021

Merged
byroot merged 1 commit into
ruby:masterfrom
mame:fix-error-line-number
Jun 18, 2026
Merged

Fix off-by-one line number in parse error messages#1021
byroot merged 1 commit into
ruby:masterfrom
mame:fix-error-line-number

Conversation

@mame

@mame mame commented Jun 18, 2026

Copy link
Copy Markdown
Member

Parse error messages report the line number one too low whenever the error is past the first line.

require "json"
JSON.parse("[1,\n@")
# expected: unexpected character: '@' at line 2 column 1
# actual:   unexpected character: '@' at line 1 column 1

@byroot

byroot commented Jun 18, 2026

Copy link
Copy Markdown
Member

Looks like the same bug is present on JRuby :)

cursor_position consumed the newline ending the previous line (post-decrement)
before counting lines, so any error past the first line was reported one line
too low (e.g. "[1,\n@" reported '@' at line 1 instead of line 2). Count that
newline when the column loop breaks on it.

Co-Authored-By: Jean Boussier <jean.boussier@gmail.com>
@byroot byroot force-pushed the fix-error-line-number branch from 52fe7f4 to 5686cef Compare June 18, 2026 18:16
@byroot byroot merged commit 82b6b21 into ruby:master Jun 18, 2026
42 checks passed
@mame mame deleted the fix-error-line-number branch June 18, 2026 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants