Skip to content
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

Psalm ignores functions with certain @since annotations, and then reports a ParseError #10761

Closed
anomiex opened this issue Feb 29, 2024 · 4 comments · Fixed by #10769
Closed

Comments

@anomiex
Copy link

anomiex commented Feb 29, 2024

It seems that Psalm is interpreting a @since docblock annotation, when the value matches /^[4578]\.\d(\.\d+)?$/, as indicating a PHP version (ref) and ignores the function definition if the value is newer than (a mangled version of1) the value of --php-version or <psalm phpVersion> (ref1, ref2).

Then, since the function was ignored, Psalm later reports a ParseError about "$storage should not be null" because it doesn't know anything about the function (cf. #9672 (comment)).

This interferes with the common (and documented) use of @since to indicate the version of the project in which a function was added.

See https://psalm.dev/r/b16dc9cdc5 for an example.

Footnotes

  1. Due to another bug in the code (here and here), it interprets any phpVersion "8.x" as if it were "8.8", any "7.x" as if it were "7.7", and so on.

Copy link

I found these snippets:

https://psalm.dev/r/b16dc9cdc5
<?php

class Foo {
    /**
     * @since 8.9.9
     */
    public function bar() {
    }
}
Psalm output (using commit b940c7e):

ERROR: ParseError - 7:5 - Problem loading method: $storage should not be null for Foo::bar

INFO: UnusedClass - 3:7 - Class Foo is never used

@kkmuffme
Copy link
Contributor

Yeah, this is something that has annoyed me before too.
I think the current behavior should only apply to the .phpstub PHP native functions/methods + PHP extensions Psalm ships with and extension stubs that are enabled in config.

For any analyzed code, including user provided stubs, the @SInCE tag should be ignored, I'd say.

@danog @weirdan what do you think?

weirdan added a commit to weirdan/psalm that referenced this issue Mar 1, 2024
@kkmuffme
Copy link
Contributor

kkmuffme commented Mar 2, 2024

Due to another bug in the code (here and here), it interprets any phpVersion "8.x" as if it were "8.8", any "7.x" as if it were "7.7", and so on.

This has been fixed by #10764 now.

kkmuffme added a commit to kkmuffme/psalm that referenced this issue Mar 2, 2024
kkmuffme added a commit to kkmuffme/psalm that referenced this issue Mar 2, 2024
kkmuffme added a commit to kkmuffme/psalm that referenced this issue Mar 2, 2024
@kkmuffme
Copy link
Contributor

kkmuffme commented Mar 2, 2024

Added a PR to only use @SInCE for php version in .phpstub files and if @since 8.3.0 PHP with "PHP" as description is used.

Now only the Problem loading method: $storage should not be null for Foo::bar is left to fix if your psalm analysis version is e.g. 7.4 but you use a .phpstub stubbed function which has @since 8.0 (or a non-stubbed function with @since 8.9.9 PHP)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants