-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Incorrect start line for trait that has a conditional class_alias in the same file #738
Comments
Probably related to empty optional attributes before the trait. |
@nikic would that roughly refer to this part of the lexer:
Because that seemed to be where things went awry, but I wasn't sure. |
I've added a test in #739. |
I wasn't able to dig in much further, but realized I should breakpoint in the Trait_ constructor which let me see it was in this callback
|
I've tried to discern this:
but I have no idea how to influence |
This was pretty tricky... I'm not completely confident in my fix. Let's see if there will be any regressions in other position information :) |
@mglaman FYI you can play with phpstan/phpstan dev-master as I just upgraded to PHP-Parser with the fix :) |
😱 @nikic thanks! @ondrejmirtes I will! Seriously, thank you. I'm going to try this today. |
🥳 The build passes with phpstan:dev-master mglaman/phpstan-drupal#149 Thank you both! |
@mglaman Thank you for reporting and investigation. We had this bug in @Rector for weeks rectorphp/rector#4556 I assumed it's somewhere in our side, so it's feels good to see we're not the only ones :) thank you! @nikic Thank you for the fix and fast release 👍 |
I have been tracking a weird bug in phpstan-drupal where PHPStan cannot discover a trait provided by Drupal. There is a PHPUnit compatibility trait used in Drupal's PHPUnit tests. It uses a dynamic alias to support both PHPUnit 6 and 7.
This is the trait in question: https://git.drupalcode.org/project/drupal/-/blob/8.8.x/core/tests/Drupal/Tests/PhpunitCompatibilityTrait.php.
PHP's internal reflection says the start line is on line 17. However,
nikic/php-parser
says it is on line 10 – the same line as theif
with aclass_exists
check.Here is a screenshot from an Xdebug session after the library parsed the file
This worked without issue in v4.9.1 but broke with v4.10.0. I haven't started to dig in entirely.
The text was updated successfully, but these errors were encountered: