Skip to content

Report an unmatched closing brace as a syntax error instead of panicking - #25

Open
danslo wants to merge 1 commit into
rectorphp:mainfrom
danslo:fix-unmatched-brace
Open

danslo wants to merge 1 commit into
rectorphp:mainfrom
danslo:fix-unmatched-brace

Conversation

@danslo

@danslo danslo commented Nov 18, 2026

Copy link
Copy Markdown

The lexer pops its state stack on every }. With nothing pushed, it indexed an empty stack, so a closing brace with nothing open panicked:

<?php }
panic: runtime error: index out of range [0] with length 0

This happens in both internal/php8/lexer.go and internal/scanner/lexer.go. The lexer now keeps its current state when there is nothing to pop, and the parser reports the syntax error. Added a parser test for }, } } and { } } with the 8.4, 7.4 and 5.6 grammars.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant