vimeo / psalm

A static analysis tool for finding errors in PHP applications
https://psalm.dev
MIT License
5.55k stars 659 forks source link

Top-level @var ignored if file has any "use" statement #6065

Open flaviovs opened 3 years ago

flaviovs commented 3 years ago

https://psalm.dev/r/b6e56c987d

Comment out the "use" statement on line 6 and the error goes away.

Swapping use and doc-block positions also gets rid of the error, but this is far from ideal since the doc-block is supposed to have file-wide documentation (this construct is very common in frameworks that use PHP as template variable, such as Yii).

psalm-github-bot[bot] commented 3 years ago

I found these snippets:

https://psalm.dev/r/b6e56c987d ```php
weirdan commented 3 years ago

While this shouldn't affect scalars, use position does matter, as it only affects the code that follows: https://3v4l.org/vMriL

So if you reference any imported classes in your docblock you would have to put it after the use.

flaviovs commented 3 years ago

Sure, with the addendum for fully qualified class names, which should also work even before use, otherwise file-level doc-blocks would be impossible.