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

Invalid static resolution from [class-string, 'method'] callable #5388

Open
vudaltsov opened this issue Mar 14, 2021 · 3 comments
Open

Invalid static resolution from [class-string, 'method'] callable #5388

vudaltsov opened this issue Mar 14, 2021 · 3 comments
Labels

Comments

@vudaltsov
Copy link
Contributor

https://psalm.dev/r/fb02f07990

@psalm-github-bot
Copy link

I found these snippets:

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

abstract class Foo
{
    final private function __construct()
    {
    }
    
    public static function create(): static
    {
        return new static();
    }
}

final class Bar extends Foo {}

/**
 * @template T
 * @param callable(): T $fn
 * @return T
 */
function test(callable $fn)
{
    return $fn();
}

// should be Bar
$var = test([Bar::class, 'create']);

/** @psalm-trace $var */
Psalm output (using commit f1a8407):

INFO: MixedAssignment - 28:1 - Unable to determine the type that $var is being assigned to

INFO: Trace - 30:25 - $var: mixed

INFO: UnusedVariable - 28:1 - $var is never referenced or the value is not used

@weirdan weirdan added the bug label Mar 14, 2021
@orklah
Copy link
Collaborator

orklah commented Apr 8, 2021

Seems unrelated to class-string usage. No syntax is recognized here:
https://psalm.dev/r/3fa6de4edb

@psalm-github-bot
Copy link

I found these snippets:

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

abstract class Foo
{
    final public function __construct()
    {
    }
    
    public static function create(): static
    {
        return new static();
    }
}

final class Bar extends Foo {}

/**
 * @template T
 * @param callable(): T $fn
 * @return T
 */
function test(callable $fn)
{
    return $fn();
}

// should be Bar
$var = test([Bar::class, 'create']);
$var = test([new Bar(), 'create']);
$var = test(['Bar', 'create']);
$var = test('Bar::create');

/** @psalm-trace $var */
Psalm output (using commit 5f4a211):

INFO: MixedAssignment - 28:1 - Unable to determine the type that $var is being assigned to

INFO: MixedAssignment - 29:1 - Unable to determine the type that $var is being assigned to

INFO: MixedAssignment - 30:1 - Unable to determine the type that $var is being assigned to

INFO: MixedAssignment - 31:1 - Unable to determine the type that $var is being assigned to

INFO: Trace - 33:25 - $var: mixed

INFO: UnusedVariable - 28:1 - $var is never referenced or the value is not used

INFO: UnusedVariable - 29:1 - $var is never referenced or the value is not used

INFO: UnusedVariable - 30:1 - $var is never referenced or the value is not used

INFO: UnusedVariable - 31:1 - $var is never referenced or the value is not used

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

No branches or pull requests

3 participants