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

ERROR: InvalidArgument - Argument [...] expects a public callable, but a non-public callable provided #11198

Open
michnovka opened this issue Jan 8, 2025 · 2 comments

Comments

@michnovka
Copy link
Contributor

This error is since psalm 5.24 I think, but I can reproduce it on 5.26 still

this is a perfectly valid code:

class Command
{
    /**
     * @param callable $code A callable(InputInterface $input, OutputInterface $output)
     */
    public function setCode(callable $code): void
    {
    }
}

abstract class AbstractEndlessCommand extends Command
{
   
    public function __construct(string $name = null)
    {
        parent::setCode([$this, 'runLoop']);
    }
    
    protected function runLoop(): void
    {
    }
}

Yet psalm complains:

ERROR: InvalidArgument
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']);

Here is a reproducer: https://psalm.dev/r/6bd3bf83a1

Copy link

I found these snippets:

https://psalm.dev/r/6bd3bf83a1
<?php

class Command
{
    /**
     * @param callable $code A callable(InputInterface $input, OutputInterface $output)
     */
    public function setCode(callable $code): void
    {
    }
}

abstract class AbstractEndlessCommand extends Command
{
   
    public function __construct(string $name = null)
    {
        parent::setCode([$this, 'runLoop']);
    }
    
    protected function runLoop(): void
    {
    }
}
Psalm output (using commit 765dcbf):

ERROR: InvalidArgument - 18:25 - Argument 1 of Command::setCode expects a public callable, but a non-public callable provided

@michnovka
Copy link
Contributor Author

Some related issues - #11077 and #10936 and #10935

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

1 participant