New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ParseError not helpful #6970
Comments
just run it seems there is code contained which is considered a syntax error on php 8.1 (which I use for the tooling), but the code beeing analyzed is only php 7.2+ |
Agreed 👍 Could you add it?
Same here 👍 Looks like miss-use of exception class. Where does it origin?
We use the parser from PHPStan. It cannot know if you're running PHP 8.1 on 7.2-valid code or running 7.2 on PHP 8.1-valid code. One way or another it would fail. It's better to use the same version you run in the project to avoid these. |
I have the same issue while using API-Platform. Phpstan 1.4.2 fixes this issue phpstan/phpstan#6386 However I still get the error with rector after upgrading.
Edit: Just tried it with 0.12.x.-dev and dev-main. Issue still present |
Could you share minimal repository reproducing the issue? Thank you |
minimal repository: https://github.com/jpgerdeman/rector-issue-6970 Bundling phpstan 1.4.2 should solve this. I just don't see a way to do this |
Thanks 👍 I've just cloned the repository and run: composer install
vendor/bin/rector process --dry-run And it works successfuly. Could you add failing Github Action to show the bug? |
Failing Github Action added Thank you, for looking into this |
Thanks for the update! It's more clear now. When I run Rector: vendor/bin/rector p -n --debug on PHP 7.4, I see there is a ➜ rector-issue-6970 git:(main) ✗ vendor/bin/rector p -n --debug
[parsing] tests/ExampleTest.php
PHP Parse error: syntax error, unexpected 'static' (T_STATIC) in /var/www/rector-issue-6970/vendor/api-platform/core/src/Util/ClientTrait80.php on line 18
Parse error: syntax error, unexpected 'static' (T_STATIC) in /var/www/rector-issue-6970/vendor/api-platform/core/src/Util/ClientTrait80.php on line 18 This trait contains 2 classes that are both parsed by PHPStan parser. |
Exactly! phpstan already fixed this issue in version 1.4.2 phpstan/phpstan#6386 |
The latest Rector is using PHPStan 1.4.2 version: https://github.com/rectorphp/rector/blob/main/composer.json Does it fix the issue? |
I'm trying the latest Rector dev: Rector 7c14a98e546fc6ebf58208d8e1d993f23125bf54 The issue is still there, so it's not in PHPStan. |
I've tried few modificaitons of PHPStan parser config, but I have no idea what exactly affect it there. cc @ondrejmirtes Hi Ondra, do you have any tips how to fix this one in Rector? I tried to add own rich parser - https://github.com/rectorphp/rector-src/pull/1790/files, but it caused PHPStan to forget the types of objects set in constructor. So we had to revert. I'm lost in the complex relationship of parser and lexer in the |
I'd say that PHPStan would crash with the same parse error - you're on PHP 7.4 but the source code of your app uses PHP 8. Therefore your app cannot work and the error is legit. What are your expectations and explanation? |
I'd expect the same. Cc @jpgerdeman Could you share more? |
This fix was made to fix a very special situation solving reading PHPDocs from this file: https://github.com/api-platform/core/blob/4ec515837cf696788e828a61005594fffc4cf244/src/Util/ClientTrait.php#L16 I don't know what's your situation and stack trace and why this parse error happens in your case. |
Closing as PHP versions of code and process run must be in sync: #6970 (comment) |
Bug Report
vendor/bin/rector --version
)I am running rector on my codebase and I get the following error:
a few things DX wise to note
does anyone have a tip on how I could find out which file contains said parse error?
The text was updated successfully, but these errors were encountered: