vimeo / psalm

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

InvalidArgument error introduced in 5.24 #10971

Open michnovka opened 2 months ago

michnovka commented 2 months ago

Getting this error:

ERROR: InvalidArgument at /home/superuser/scripts/dockontrol2/src/Twig/AppExtension.php:18:44 Argument 2 of Twig\TwigFilter::__construct expects a public static callable, but a non-static callable provided (see https://psalm.dev/004) new TwigFilter('time_tooltip', [TimeRuntime::class, 'createTimeTooltip'], [

With the below code

new TwigFilter('time_tooltip', [TimeRuntime::class, 'createTimeTooltip'], [
    'is_safe' => ['html'],
])

Note that the TwigFilter source does not specify static nor public property for callable:

final class TwigFilter
{
    /**
     * @param callable|array{class-string, string}|null $callable A callable implementing the filter. If null, you need to overwrite the "node_class" option to customize compilation.
     */
    public function __construct(string $name, $callable = null, array $options = [])
    {

I am unable to reproduce this on psalm.dev

I am getting this on all projects with psalm 5.24, but it works fine with 5.23

michnovka commented 2 months ago

I did check for any stubs used, but in the whole project there is no stub for TwigFilter class. I do use psalm/plugin-symfony v 5.1.0, but this stub is not there. So Id assume it reads signature from the source code (vendor/twig/twig/src/TwigFilter.php)

michnovka commented 2 months ago

Also please note that this syntax is in line with official Symfony docs for Lazy loaded twig extensions

michnovka commented 4 weeks ago

This error is showing up on more places now. E.g. in the Syfony\Console\Command\Command::setCode() function.

ERROR: InvalidArgument - src/Command/AbstractEndlessCommand.php:55:25 - Argument 1 of Symfony\Component\Console\Command\Command::setCode expects a public callable, but a non-public callable provided (see https://psalm.dev/004)
        parent::setCode([$this, 'runloop']);

when I use protected modifier for function runloop. I repeat, there is no psalm param specification requiring that the callable should be public, nonstatic or whatever. Only callable. And I am unable to reproduce this on psalm.dev - https://psalm.dev/r/3c405968f1

Version 5.23 works just fine

psalm-github-bot[bot] commented 4 weeks ago

I found these snippets:

https://psalm.dev/r/3c405968f1 ```php
michnovka commented 4 weeks ago

Aha, the reason why I cannot reproduce this issue on psalm.dev is because it uses this version:

https://github.com/vimeo/psalm/blob/16b24bdc94e052b5ce69fd232a77416a1f6ec3e6/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentAnalyzer.php

Which does not contain the breaking PR #10839

@weirdan can you please look into this, as you reviewed the change and also it seems you are in charge of merging code into master branch, which is what psalm.dev uses?

VincentLanglet commented 4 weeks ago

You can close the issue because it's already fixed in https://github.com/vimeo/psalm/pull/10935.

Just wait for a new release.

michnovka commented 3 weeks ago

The issue from the initial message here is resolved, but the issue with setting protected function remains. Should I close this one and open a new one, or keep this one open?

See https://github.com/vimeo/psalm/pull/10935#issuecomment-2182247241

https://3v4l.org/k9tTa

https://psalm.dev/r/842a7f605a