rector: RichParser error on dev-main on PHP 7.4
Bug Report
Subject | Details |
---|---|
Rector version | dev-main |
@TomasVotruba I tried rector dev-main on https://github.com/codeigniter4/CodeIgniter4/pull/5269 to test the compatibility with PHPStan 1.0, and this only show this error on PHP 7.4, ref https://github.com/codeigniter4/CodeIgniter4/runs/4066534747?check_suite_focus=true#step:10:5
➜ CodeIgniter4 git:(upgrade-to-phpstan1) ✗ /opt/homebrew/Cellar/php@7.4/7.4.24_1/bin/php vendor/bin/rector process tests/system/View/TableTest.php --clear-cache -vvv
[parsing] tests/system/View/TableTest.php
In RichParser.php line 38:
[PHPStan\Parser\ParserErrorsException]
Syntax error, unexpected T_FUNCTION, expecting T_VARIABLE on line 117, Syntax error, unexpected '}', expecting T_VARIABLE on line 144, Syntax error, unexpected '}', expecting T_VARI
ABLE on line 167, Syntax error, unexpected '}', expecting T_VARIABLE on line 818, Syntax error, unexpected T_PUBLIC on line 1018
while it is working ok on PHP 8.0. It seems there is invalid syntax in PHP 7.4 for PHPStan.
/cc @ondrejmirtes do you think it is PHPStan issue on downgrading syntax ?
The trace exception message are like this:
[parsing] tests/system/View/TableTest.php
In RichParser.php line 38:
[PHPStan\Parser\ParserErrorsException]
Syntax error, unexpected T_FUNCTION, expecting T_VARIABLE on line 117, Syntax error, unexpected '}', expecting T_VARIABLE on line 144, Syntax error, unexpected '}', expecting T_VARI
ABLE on line 167, Syntax error, unexpected '}', expecting T_VARIABLE on line 818, Syntax error, unexpected T_PUBLIC on line 1018
Exception trace:
at phar:///Users/samsonasik/www/CodeIgniter4/vendor/rector/rector/vendor/phpstan/phpstan/phpstan.phar/src/Parser/RichParser.php:38
PHPStan\Parser\RichParser->parseFile() at phar:///Users/samsonasik/www/CodeIgniter4/vendor/rector/rector/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/Php/PhpMethodReflection.php:217
PHPStan\Reflection\Php\PhpMethodReflection->isVariadic() at phar:///Users/samsonasik/www/CodeIgniter4/vendor/rector/rector/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/Php/PhpMethodReflection.php:183
PHPStan\Reflection\Php\PhpMethodReflection->getVariants() at phar:///Users/samsonasik/www/CodeIgniter4/vendor/rector/rector/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/Php/UniversalObjectCratesClassReflectionExtension.php:50
PHPStan\Reflection\Php\UniversalObjectCratesClassReflectionExtension->getProperty() at phar:///Users/samsonasik/www/CodeIgniter4/vendor/rector/rector/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/ClassReflection.php:377
PHPStan\Reflection\ClassReflection->getProperty() at phar:///Users/samsonasik/www/CodeIgniter4/vendor/rector/rector/vendor/phpstan/phpstan/phpstan.phar/src/Type/ObjectType.php:121
PHPStan\Type\ObjectType->getUnresolvedPropertyPrototype() at phar:///Users/samsonasik/www/CodeIgniter4/vendor/rector/rector/vendor/phpstan/phpstan/phpstan.phar/src/Type/ObjectType.php:98
PHPStan\Type\ObjectType->getProperty() at phar:///Users/samsonasik/www/CodeIgniter4/vendor/rector/rector/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php:2624
PHPStan\Analyser\NodeScopeResolver->processAssignVar() at phar:///Users/samsonasik/www/CodeIgniter4/vendor/rector/rector/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php:1353
PHPStan\Analyser\NodeScopeResolver->processExprNode() at phar:///Users/samsonasik/www/CodeIgniter4/vendor/rector/rector/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php:451
PHPStan\Analyser\NodeScopeResolver->processStmtNode() at phar:///Users/samsonasik/www/CodeIgniter4/vendor/rector/rector/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php:249
PHPStan\Analyser\NodeScopeResolver->processStmtNodes() at phar:///Users/samsonasik/www/CodeIgniter4/vendor/rector/rector/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php:414
PHPStan\Analyser\NodeScopeResolver->processStmtNode() at phar:///Users/samsonasik/www/CodeIgniter4/vendor/rector/rector/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php:249
PHPStan\Analyser\NodeScopeResolver->processStmtNodes() at phar:///Users/samsonasik/www/CodeIgniter4/vendor/rector/rector/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php:498
PHPStan\Analyser\NodeScopeResolver->processStmtNode() at phar:///Users/samsonasik/www/CodeIgniter4/vendor/rector/rector/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php:249
PHPStan\Analyser\NodeScopeResolver->processStmtNodes() at phar:///Users/samsonasik/www/CodeIgniter4/vendor/rector/rector/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php:464
PHPStan\Analyser\NodeScopeResolver->processStmtNode() at phar:///Users/samsonasik/www/CodeIgniter4/vendor/rector/rector/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php:217
PHPStan\Analyser\NodeScopeResolver->processNodes() at /Users/samsonasik/www/CodeIgniter4/vendor/rector/rector/packages/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php:152
Rector\NodeTypeResolver\PHPStan\Scope\PHPStanNodeScopeResolver->processNodesWithMixinHandling() at /Users/samsonasik/www/CodeIgniter4/vendor/rector/rector/packages/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php:140
Rector\NodeTypeResolver\PHPStan\Scope\PHPStanNodeScopeResolver->processNodes() at /Users/samsonasik/www/CodeIgniter4/vendor/rector/rector/packages/NodeTypeResolver/NodeScopeAndMetadataDecorator.php:81
Rector\NodeTypeResolver\NodeScopeAndMetadataDecorator->decorateNodesFromFile() at /Users/samsonasik/www/CodeIgniter4/vendor/rector/rector/src/Application/FileProcessor.php:44
Rector\Core\Application\FileProcessor->parseFileInfoToLocalCache() at /Users/samsonasik/www/CodeIgniter4/vendor/rector/rector/src/Application/FileProcessor/PhpFileProcessor.php:80
Rector\Core\Application\FileProcessor\PhpFileProcessor->Rector\Core\Application\FileProcessor\{closure}() at /Users/samsonasik/www/CodeIgniter4/vendor/rector/rector/src/Application/FileProcessor/PhpFileProcessor.php:144
Rector\Core\Application\FileProcessor\PhpFileProcessor->tryCatchWrapper() at /Users/samsonasik/www/CodeIgniter4/vendor/rector/rector/src/Application/FileProcessor/PhpFileProcessor.php:81
Rector\Core\Application\FileProcessor\PhpFileProcessor->process() at /Users/samsonasik/www/CodeIgniter4/vendor/rector/rector/src/Application/ApplicationFileProcessor.php:76
Rector\Core\Application\ApplicationFileProcessor->processFiles() at /Users/samsonasik/www/CodeIgniter4/vendor/rector/rector/src/Application/ApplicationFileProcessor.php:57
Rector\Core\Application\ApplicationFileProcessor->run() at /Users/samsonasik/www/CodeIgniter4/vendor/rector/rector/src/Console/Command/ProcessCommand.php:152
Rector\Core\Console\Command\ProcessCommand->execute() at /Users/samsonasik/www/CodeIgniter4/vendor/rector/rector/vendor/symfony/console/Command/Command.php:274
RectorPrefix20211031\Symfony\Component\Console\Command\Command->run() at /Users/samsonasik/www/CodeIgniter4/vendor/rector/rector/vendor/symfony/console/Application.php:870
RectorPrefix20211031\Symfony\Component\Console\Application->doRunCommand() at /Users/samsonasik/www/CodeIgniter4/vendor/rector/rector/vendor/symfony/console/Application.php:266
RectorPrefix20211031\Symfony\Component\Console\Application->doRun() at /Users/samsonasik/www/CodeIgniter4/vendor/rector/rector/src/Console/ConsoleApplication.php:71
Rector\Core\Console\ConsoleApplication->doRun() at /Users/samsonasik/www/CodeIgniter4/vendor/rector/rector/vendor/symfony/console/Application.php:162
RectorPrefix20211031\Symfony\Component\Console\Application->run() at /Users/samsonasik/www/CodeIgniter4/vendor/rector/rector/bin/rector.php:63
require_once() at /Users/samsonasik/www/CodeIgniter4/vendor/rector/rector/bin/rector:5
process [-n|--dry-run] [-a|--autoload-file AUTOLOAD-FILE] [-o|--output-format [OUTPUT-FORMAT]] [--no-progress-bar] [--no-diffs] [--clear-cache] [--] [<source>...]
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 25 (25 by maintainers)
Yeah, I think so, there’s no syntax in PHP 5 that was removed later.
Just submitted a fix for this: https://github.com/rectorphp/rector-src/pull/1184
The problem was that Rector uses (based on my advice which I haven’t realized might be wrong for this use-case) “current version PHP parser”. And that doesn’t work when phpstorm-stubs need to be parsed.
PHPStan doesn’t have this problem thanks to “PathRoutingParser”: https://github.com/phpstan/phpstan-src/blob/master/src/Parser/PathRoutingParser.php (PHPStan wants to get parse errors when user writes PHP 8 code on PHP 7.x but still needs to parse phpstorm-stubs with PHP 8 parser).
I think for Rector it’s best to just always use PHP 8 parser.
Alright 😊
@TomasVotruba I’m busy this weekend, what about Monday morning?