Skip to content

Fix error columns after lines with multibyte characters - #1988

Draft
spawnia wants to merge 2 commits into
masterfrom
fix-source-location-columns
Draft

spawnia wants to merge 2 commits into
masterfrom
fix-source-location-columns

Conversation

@spawnia

@spawnia spawnia commented Oct 3, 2026 •

Copy link
Copy Markdown
Collaborator

Syntax error columns are wrong after any line that contains a multibyte character.
Source::getLocation() subtracted a byte offset from a character position.
It now counts the characters after the last line terminator.

Document Before After
{ a }\nxx? 2:1 2:1
# ä\n{ a }\nxx? 3:0 3:1
# äää\nxx? 2:-2 2:1
Found by Copilot on https://github.com//pull/1987

#1987 (comment) reported the wrong column for invalid UTF-8 after a multibyte line.
The cause is older than that pull request and affects every syntax error.

🤖 Generated with Claude Code

Source::getLocation() subtracted the byte offset of the last line terminator
from a character position, so every multibyte character on earlier lines
shifted the column to the left, down to zero or negative values.

🤖 Generated with Claude Code
🤖 Generated with Claude Code

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The implementation correctly handles character offsets and includes focused regression coverage.

Review effort: Balanced
Findings: None

What changed in this PR

Fixes source-location columns following multibyte characters by calculating the current line’s character length.

Changes:

  • Splits the source prefix into lines to derive accurate line and column values.
  • Adds coverage for multibyte characters and varied line separators.
  • Documents the fix.
File Description
src/​Language/​Source.php Corrects line and column calculation.
tests/​Language/​SourceTest.php Adds source-location regression tests.
CHANGELOG.md Records the fix.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

This branch has not been deployed

No deployments
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