microsoft / microsoft/tolerant-php-parser
throw expression is not parsed correctly inside a ternary
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 894
- Forks
- 85
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 3
Description
Reproducible with the following snippet:
<?php
return rand() ? throw new Exception() : 42;
And test code, using dev-main:
<?php
require __DIR__ . "/vendor/autoload.php";
use Microsoft\PhpParser\Parser;
$parser = new Parser();
$astNode = $parser->parseSourceFile('<?php return rand() ? throw new Exception() : 42;');
print_r($astNode);
The resulting ternary node has an empty ifExpression, the throw expression inside elseExpression, and then the 42 to follow as a separate expression.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with Microsoft\PhpParser\Parser::parseSourceFile using the reproducible PHP snippet in the issue. Inspect the AST produced for the ternary containing a throw expression and compare it with the intended expression structure. Done means the ternary node represents the throw expression and the value 42 in the correct branches, without leaving 42 as a separate expression.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100