InvalidArgumentException with message 'Unable to find type name' if using union return types
Radiergummi opened this issue · 1 comments
Radiergummi commented
Defining a function with a union return type inside psysh yields the error Unable to find type name:
function x(): int|null
{
return null;
}
I can't quite pin it down, however - sometimes it works, sometimes it doesn't. Anyone got an idea why?
Full output for reference:
>_< Styx Projects $ psysh -vvv
Psy Shell v0.11.5 (PHP 8.1.2 — cli) by Justin Hileman
> function x(string $base32): int|null
... {
... return null;
... }
InvalidArgumentException with message 'Unable to find type name'
--
<class></class>() at /Users/moritz/.composer/vendor/psy/psysh/src/CodeCleaner/ReturnTypePass.php:116
<class>Psy\CodeCleaner\ReturnTypePass</class>->typeName() at /Users/moritz/.composer/vendor/psy/psysh/src/CodeCleaner/ReturnTypePass.php:65
<class>Psy\CodeCleaner\ReturnTypePass</class>->enterNode() at /Users/moritz/.composer/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php:200
<class>PhpParser\NodeTraverser</class>->traverseArray() at /Users/moritz/.composer/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php:114
<class>PhpParser\NodeTraverser</class>->traverseNode() at /Users/moritz/.composer/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php:223
<class>PhpParser\NodeTraverser</class>->traverseArray() at /Users/moritz/.composer/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php:114
<class>PhpParser\NodeTraverser</class>->traverseNode() at /Users/moritz/.composer/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php:223
<class>PhpParser\NodeTraverser</class>->traverseArray() at /Users/moritz/.composer/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php:91
<class>PhpParser\NodeTraverser</class>->traverse() at /Users/moritz/.composer/vendor/psy/psysh/src/CodeCleaner.php:273
<class>Psy\CodeCleaner</class>->clean() at /Users/moritz/.composer/vendor/psy/psysh/src/Shell.php:854
<class>Psy\Shell</class>->addCode() at /Users/moritz/.composer/vendor/psy/psysh/src/Shell.php:537
<class>Psy\Shell</class>->getInput() at /Users/moritz/.composer/vendor/psy/psysh/src/ExecutionLoopClosure.php:40
<class></class>Psy\{closure}() at /Users/moritz/.composer/vendor/psy/psysh/src/ExecutionClosure.php:89
<class>Psy\ExecutionClosure</class>->execute() at /Users/moritz/.composer/vendor/psy/psysh/src/Shell.php:383
<class>Psy\Shell</class>->doInteractiveRun() at /Users/moritz/.composer/vendor/psy/psysh/src/Shell.php:354
<class>Psy\Shell</class>->doRun() at /Users/moritz/.composer/vendor/symfony/console/Application.php:171
<class>Symfony\Component\Console\Application</class>->run() at /Users/moritz/.composer/vendor/psy/psysh/src/Shell.php:329
<class>Psy\Shell</class>->run() at /Users/moritz/.composer/vendor/psy/psysh/src/functions.php:428
<class></class>Psy\{closure}() at /Users/moritz/.composer/vendor/psy/psysh/bin/psysh:148
<class></class>include() at /Users/moritz/.composer/vendor/bin/psysh:107
bobthecow commented
Thanks for the bug report. I've pushed a fix, which will be available in the next stable release.