Skip to content
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

Closed
staabm opened this issue Jan 25, 2022 · 16 comments · Fixed by rectorphp/rector-src#1789
Closed

ParseError not helpful #6970

staabm opened this issue Jan 25, 2022 · 16 comments · Fixed by rectorphp/rector-src#1789
Assignees
Labels

Comments

@staabm
Copy link
Contributor

staabm commented Jan 25, 2022

Bug Report

Subject Details
Rector version e.g. v0.12.13 (invoke vendor/bin/rector --version)

I am running rector on my codebase and I get the following error:

 [ERROR] Could not process "models/mappers/Viewakstatus.php" file, due to:
         "Analyze error: "ParseError (syntax error, unexpected variable "$select") thrown while looking for class
         Clx_Paginator_Adapter_Mapper.". Include your files in "$parameters->set(Option::AUTOLOAD_PATHS, [...]);" or
         "$parameters->set(Option::BOOTSTRAP_FILES, [...]);" in "rector.php" config.
         See https://github.com/rectorphp/rector#configuration#0

a few things DX wise to note

  • it would be great if the error message could contain a path to the file containing the syntax error (as I cannot find a file in the project with such an error)
  • the hint regarding "check the autoload-path" seems to be not really helpful in context of a ParseError

does anyone have a tip on how I could find out which file contains said parse error?

@staabm staabm added the bug label Jan 25, 2022
@staabm
Copy link
Contributor Author

staabm commented Jan 25, 2022

just run parallel-lint on my codebase.

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+

@TomasVotruba
Copy link
Member

TomasVotruba commented Jan 25, 2022

it would be great if the error message could contain a path to the file containing the syntax error (as I cannot find a file in the project with such an error)

Agreed 👍 Could you add it?

the hint regarding "check the autoload-path" seems to be not really helpful in context of a ParseError

Same here 👍 Looks like miss-use of exception class. Where does it origin?

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+

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.

@jpgerdeman
Copy link

jpgerdeman commented Jan 27, 2022

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.

Subject Detail
rector/rector 0.12.15
phpstan/phpstan 1.4.2
Api-Platform 2.6.8

Edit: Just tried it with 0.12.x.-dev and dev-main. Issue still present

@TomasVotruba
Copy link
Member

Could you share minimal repository reproducing the issue? Thank you

@jpgerdeman
Copy link

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

@TomasVotruba
Copy link
Member

TomasVotruba commented Jan 27, 2022

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?

@jpgerdeman
Copy link

jpgerdeman commented Feb 8, 2022

Failing Github Action added
https://github.com/jpgerdeman/rector-issue-6970/actions/runs/1812241792

Thank you, for looking into this

@TomasVotruba
Copy link
Member

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 static type. This type is available since PHP 8.0 (https://php.watch/versions/8.0/static-return-type), so this error is expected.

➜  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.

@jpgerdeman
Copy link

Exactly!

phpstan already fixed this issue in version 1.4.2 phpstan/phpstan#6386
The prefixed phpstan version that comes with rector needs to be updated.

@TomasVotruba
Copy link
Member

TomasVotruba commented Feb 8, 2022

The latest Rector is using PHPStan 1.4.2 version: https://github.com/rectorphp/rector/blob/main/composer.json

Does it fix the issue?

@TomasVotruba
Copy link
Member

I'm trying the latest Rector dev:

Rector 7c14a98e546fc6ebf58208d8e1d993f23125bf54

The issue is still there, so it's not in PHPStan.

@TomasVotruba
Copy link
Member

TomasVotruba commented Feb 9, 2022

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 parser.neon config, so any help is much appreciated.

@ondrejmirtes
Copy link
Contributor

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?

@TomasVotruba
Copy link
Member

I'd expect the same.
But there is referenced fix in PHPStan, that makes it possible: phpstan/phpstan#6386

Cc @jpgerdeman Could you share more?

@ondrejmirtes
Copy link
Contributor

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.

@TomasVotruba
Copy link
Member

TomasVotruba commented Feb 23, 2022

Closing as PHP versions of code and process run must be in sync: #6970 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants