-
-
Notifications
You must be signed in to change notification settings - Fork 864
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
Shebang breaks @var namespace resolution #6252
Comments
I am experiencing this issue as well and can confirm, that it did work in v1.2. Specifically, the commit that broke it is phpstan/phpstan-src@256d11b8. I was digging a bit deeper today and traced the problem down to $nameScopeKey = $this->getNameScopeKey($originalClassFileName, $className, $lookForTrait, $functionName);
if (
$node instanceof Node\Stmt
&& !$node instanceof Node\Stmt\Namespace_
&& !$node instanceof Node\Stmt\Declare_
&& !$node instanceof Node\Stmt\DeclareDeclare
&& !$node instanceof Node\Stmt\Use_
&& !$node instanceof Node\Stmt\UseUse
&& !$node instanceof Node\Stmt\GroupUse
&& !$node instanceof Node\Stmt\TraitUse
&& !$node instanceof Node\Stmt\TraitUseAdaptation
&& !array_key_exists($nameScopeKey, $nameScopeMap)
) {
$nameScopeMap[$nameScopeKey] = static fn (): NameScope => new NameScope(
$namespace,
$uses,
$className,
$functionName,
($typeMapCb !== null ? $typeMapCb() : TemplateTypeMap::createEmpty()),
$typeAliasesMap,
);
} If we assume to analyze the following snippet: #!/usr/bin/env php
<?php
use FooNamespace\FooClass;
/** @var FooClass $f */ then the
Now the problem is, that the second That's as far as my digging went, but unfortunately I don't have the necessary insight into the internal workings of PHPStan to figure out what would be the correct approach to solve this issue. Any suggestions? @ondrejmirtes |
@martin-heralecky Thank you for your research, it seems like you'd be capable at fixing PHPStan bugs! :) I fixed this one: phpstan/phpstan-src@c87284a |
Excellent! When can we expect this to be released? |
Later today |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Bug report
Adding a shebang to a script breaks @var namespace resolution.
Worked until v1.2
Broken in v1.3
Code snippet that reproduces the problem
https://phpstan.org/r/43479d60-e6c5-4319-916a-db41b72942f8
The text was updated successfully, but these errors were encountered: