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

InvalidArgument error introduced in 5.24 #10971

Open
michnovka opened this issue May 11, 2024 · 7 comments
Open

InvalidArgument error introduced in 5.24 #10971

michnovka opened this issue May 11, 2024 · 7 comments

Comments

@michnovka
Copy link
Contributor

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
Copy link
Contributor Author

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
Copy link
Contributor Author

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

@michnovka
Copy link
Contributor Author

michnovka commented Jun 19, 2024

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

Copy link

I found these snippets:

https://psalm.dev/r/3c405968f1
<?php

class Command{
    /**
     * @param callable $code
     */
	public function setCode(callable $code): static
    {
        return $this;
    }
}

class Code extends Command{
    public function __construct(){
        parent::setCode([$this, 'runCode']);
    }
    
    protected function runCode(): void
    {}
}
Psalm output (using commit 16b24bd):

No issues!

@michnovka
Copy link
Contributor Author

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
Copy link
Contributor

You can close the issue because it's already fixed in #10935.

Just wait for a new release.

@michnovka
Copy link
Contributor Author

michnovka commented Jun 21, 2024

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 #10935 (comment)

https://3v4l.org/k9tTa

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

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

No branches or pull requests

2 participants