Mixed, by-reference varargs parameter gets handled like an intersection type and throws a fatal error
asmundstavdahl opened this issue · 0 comments
asmundstavdahl commented
- PHP Depend version: 2.11.1
- PHP Version: 7.4, 8.0, 8.1
- Installation type: composer
- Operating System / Distribution & Version: Ubuntu 20.04.5
Current Behavior
Parsing a file that contains a function signature with a mixed-type by-reference varargs parameter (e.g. function f(mixed &...$vars){}
throws the following error:
PHP Fatal error: Uncaught TypeError: Argument 1 passed to PDepend\Source\AST\AbstractASTNode::addChild() must implement interface PDepend\Source\AST\ASTNode, null given, called in …/vendor/pdepend/pdepend/src/main/php/PDepend/Source/Language/PHP/PHPParserVersion81.php on line 198 and defined in …/vendor/pdepend/pdepend/src/main/php/PDepend/Source/AST/AbstractASTNode.php:413
Stack trace:
#0 …/vendor/pdepend/pdepend/src/main/php/PDepend/Source/Language/PHP/PHPParserVersion81.php(198): PDepend\Source\AST\AbstractASTNode->addChild()
#1 …/vendor/pdepend/pdepend/src/main/php/PDepend/Source/Language/PHP/PHPParserVersion81.php(225): PDepend\Source\Language\PHP\PHPParserVersion81->parseIntersectionTypeHint()
#2 …/vendor/pdepend/pdepend/src/main/php/PDepend/Source/Language/PHP/PHPParserVersion81.php(238): PDepend\Source\Language\PHP\PHPParserVersion81->parseIntersectionOrUnionTypeHint()
#3 /ho in …/vendor/pdepend/pdepend/src/main/php/PDepend/Source/AST/AbstractASTNode.php on line 413
Some debugging reveals that the parameter is parsed as an intersection of mixed
and Tokens::T_ELLIPSIS
, which does not make sense.
Expected Behavior
It is a valid function signature, so parsing should succeed.
Steps To Reproduce:
- Make a file test.php with the contents
<?php function f(mixed &...$vars){}
- Run pdepend on test.php
Checks before submitting
- Be sure that there isn't already an issue about this. See: Issues list
- Be sure that there isn't already a pull request about this. See: Pull requests
- I have added every step to reproduce the bug.
- If possible I added relevant code examples.
- This issue is about 1 bug and nothing more.
- The issue has a descriptive title. For example: "Default value is not available in AST when it's an array".