-
Notifications
You must be signed in to change notification settings - Fork 660
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
UnevaluatedCode for declare
with return
#8892
Comments
I found these snippets: https://psalm.dev/r/d4d61a5673<?php
declare(strict_types=1);
return [];
https://psalm.dev/r/49ce4900b9<?php
declare(strict_types=1);
namespace App;
return [];
|
There's a fault in Psalm handling of statements in and out namespaces What happens here is:
There's a reason to that though, because any statement in the file could use any symbol also declared in the file, no matter the order of the statements. So I guess, we would need to first extract symbols, collect leftover statement for each namespace and then process statements in the correct context and in order(so declare first, then leftovers by namespace). This may be a big change to support a very unusual pattern though... What I'm more worried about is the fact that the declare is analyzed at then end (after namespaces) so I'm not sure it's correctly processed when analyzing other statements |
Indeed: https://psalm.dev/r/3a0287fa0f |
I found these snippets: https://psalm.dev/r/3a0287fa0f<?php declare(strict_types=1);
// namespace NS;
function f(int $_i): void {}
function ff(string|int $a): void {
atan($a);
/** @psalm-check-type $a = int */;
f($a); // expected: no issues here. If $a was a string, there would be an exception thrown on atan() call
}
|
This issue can be now closed! |
Yes, this specific issue has been fixed. For future reference, #8892 (comment) still holds and the way Psalm process this is not optimal (and lead to very marginal edge cases for files that would contain a strict type declaration and namespace that have expressions that need to be evaluated) |
It works in global namespace:
https://psalm.dev/r/d4d61a5673
but it throws an error with namespace:
https://psalm.dev/r/49ce4900b9
The text was updated successfully, but these errors were encountered: