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

Can't template based on the output of a pure function called on an input param #11121

Open
jnvsor opened this issue Oct 12, 2024 · 1 comment

Comments

@jnvsor
Copy link
Contributor

jnvsor commented Oct 12, 2024

https://psalm.dev/r/9f37666cc3

ReflectionFunctionAbstract->isInternal is stubbed pure in psalm, but there's no way to template based on the output of it.

It would also be nice to be able to template based on arbitrary constructor assignments to uninitialized properties.

Copy link

I found these snippets:

https://psalm.dev/r/9f37666cc3
<?php

declare(strict_types=1);

/**
 * @psalm-template I of bool
 */
final readonly class DeclaredCallableBag
{
    /** @psalm-var I */
    public bool $internal;
    /** @psalm-var (I is true ? null : string) */
    public ?string $filename;
    /** @psalm-var (I is true ? null : int) */
    public ?int $startline;
    /** @psalm-var (I is true ? null : int) */
    public ?int $endline;

    public function __construct(ReflectionFunctionAbstract $callable)
    {
        $this->internal = $callable->isInternal();
        $t = $callable->getFileName();
        $this->filename = false === $t ? null : $t;
        $t = $callable->getStartLine();
        $this->startline = false === $t ? null : $t;
        $t = $callable->getEndLine();
        $this->endline = false === $t ? null : $t;
    }
}
Psalm output (using commit 03ee02c):

ERROR: InvalidPropertyAssignmentValue - 21:27 - $this->internal with declared type 'I:DeclaredCallableBag as bool' cannot be assigned type 'bool'

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