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

Unbound template type is not narrowed correctly #10995

Open
mvorisek opened this issue May 28, 2024 · 2 comments
Open

Unbound template type is not narrowed correctly #10995

mvorisek opened this issue May 28, 2024 · 2 comments

Comments

@mvorisek
Copy link

mvorisek commented May 28, 2024

repro: https://psalm.dev/r/db8a695a2d and https://psalm.dev/r/ed1b1e4cfb

I expect no Psalm issue reported.

Copy link

psalm-github-bot bot commented May 28, 2024

I found these snippets:

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

class BigIntType
{
    /**
     * @template T
     * @param T $value
     * @return (T is null ? null : int|string)
     */
    public function convertToPHPValue(mixed $value): int|string|null
    {
        if ($value === null || is_int($value)) {
            return $value;
        }

        assert(is_string($value));

        // remove decimals
        $dotPos = strpos($value, '.');
        if ($dotPos !== false) {
            $value = substr($value, 0, $dotPos);
        }

        return $value;
    }
}
Psalm output (using commit 16b24bd):

ERROR: NoValue - 21:29 - All possible types for this argument were invalidated - This may be dead code

@mvorisek mvorisek changed the title assert with template is behaving wrongly Unbound template type is not narrowed correctly May 28, 2024
@mvorisek
Copy link
Author

Does anyone has an idea what is going on and how to fix it?

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