Skip to content

fix: correct #line directives for block constructs (GH #306)#416

Open
toddr-bot wants to merge 1 commit into
mainfrom
koan.toddr.bot/fix-compiled-line-numbers
Open

fix: correct #line directives for block constructs (GH #306)#416
toddr-bot wants to merge 1 commit into
mainfrom
koan.toddr.bot/fix-compiled-line-numbers

Conversation

@toddr-bot

Copy link
Copy Markdown
Contributor

Summary

  • What: Fix incorrect #line directives in compiled templates for block directives (IF, FOREACH, WHILE, TRY, SWITCH, WRAPPER, FILTER, etc.)
  • Why: Block directives spanning multiple lines reported the END tag's line number instead of the opening tag's line, making error messages point to the wrong location. Reported in Compiled templates have incorrect line numbers for IF statements #306.
  • How: The ; token value now carries the source line number. Each block directive grammar rule saves the opening tag's line via _block_start_line, which the chunk rule uses instead of the parser's current (post-END) line counter.

Testing

  • 32 new tests in t/compile_line.t covering IF, FOREACH, WHILE, TRY, SWITCH, UNLESS, WRAPPER, FILTER, nested blocks, and single-tag blocks
  • Full test suite passes (3170 existing tests)

Closes #306

🤖 Generated with Claude Code

…cts (GH #306)

Block directives (IF, FOREACH, WHILE, TRY, SWITCH, WRAPPER, FILTER, etc.)
that span multiple lines were getting #line directives pointing to the END
tag line instead of the opening tag line. This caused incorrect file/line
info in error messages from compiled templates.

Root cause: the chunk grammar rule called location() after the entire block
was parsed, at which point the parser's line counter had advanced to the
END tag. Fix: each block directive rule now saves the opening tag's line
number via _block_start_line, and the chunk rule uses it. The ';' token
value now carries the line number from its source tag, enabling accurate
line tracking for both multi-tag and single-tag block directives.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@toddr-bot

Copy link
Copy Markdown
Contributor Author

Recreated from #350 (auto-closed when the toddr-bot fork was removed). Original branch is now hosted on this repo.

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.

Compiled templates have incorrect line numbers for IF statements

1 participant