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

Incorrect inference when constructing class-string template with static #8257

Open
AndrolGenhald opened this issue Jul 13, 2022 · 1 comment

Comments

@AndrolGenhald
Copy link
Collaborator

Extension of #8200.

https://psalm.dev/r/fe2c4dfb31 new static() from Test::create() is incorrectly inferred as Test&T where T is Maybe.

@psalm-github-bot
Copy link

I found these snippets:

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

/**
 * @template-covariant A
 * @psalm-immutable
 * @psalm-consistent-constructor
 * @psalm-consistent-templates
 */
final class Maybe
{
    /**
     * @param A $value
     */
    public function __construct(public $value) {}

    /**
     * @template B
     * @param B $value
     * @return Maybe<B>
     *
     * @psalm-pure
     */
    public static function just($value): self
    {
        return new self($value);
    }
}

abstract class Test
{
    final private function __construct() {}

    /**
     * @template T of Maybe
     * @param class-string<T> $maybeClass
     */
    final public static function create(string $maybeClass = Maybe::class): static
    {
        $maybe = $maybeClass::just(new static());
        foobar($maybe->value);
        return $maybe->value;
    }
}

function foobar(Maybe $m): void {}
Psalm output (using commit 6d45003):

No issues!

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

No branches or pull requests

1 participant