🌐 US-Proxy
class="logged-out env-production page-responsive" style="word-wrap: break-word;" >
Skip to content

CallToConstructorStatementWithoutImpurePointsRule does not see @throws above called constructor #14767

Description

@ondrejmirtes

Bug report

After recent changes phpstan/phpstan-src#5798 there has been a regression. The attached code snippet is reported as an error.

Because PHPStan does not see any explicit throw points (because the condition is always false), it will mark new FileIteratorSourceLocator([1, 2, 3]) as unused. But in fact the user is expecting the condition to be thrown.

We COULD get explicit throw points even from dead code branches but right now everything from them is thrown away (https://github.com/phpstan/phpstan-src/blob/7fe8b00282cff26f814cbddbec9906a1f4802301/src/Analyser/NodeScopeResolver.php#L1317) so I don't want to change that precedent.

Instead, we could also take @throws above the involved constructors/functions/methods from the WHOLE TRANSITIVE CHAIN into account.

Please add tests to all rules that were changed in the original linked PR, to make sure the implementation is correct.

Code snippet that reproduces the problem

https://phpstan.org/r/1f7b2f5d-3117-4e74-bb2a-61521dbbf40e

Expected output

"Call to new FileIteratorSourceLocator() on a separate line has no effect." should not be reported

Did PHPStan help you today? Did it make you happy in any way?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions