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

Nested templates regression since 5.3 #9241

Closed
vudaltsov opened this issue Feb 8, 2023 · 5 comments
Closed

Nested templates regression since 5.3 #9241

vudaltsov opened this issue Feb 8, 2023 · 5 comments

Comments

@vudaltsov
Copy link
Contributor

Here's what Psalm v5.2 correctly reports for https://psalm.dev/r/af716b51e1:

ERROR: InvalidReturnType - .stuff/test.php:37:44 - The declared return type 'int' for IntValueProcessor::process is incorrect, got '''' (see https://psalm.dev/011)
    public function process(Value $value): mixed


ERROR: InvalidReturnStatement - .stuff/test.php:39:16 - The inferred type '''' does not match the declared return type 'int' for IntValueProcessor::process (see https://psalm.dev/128)
        return '';

Psalm v5.3 reports No issues!

@psalm-github-bot
Copy link

I found these snippets:

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

declare(strict_types=1);

/**
 * @template T
 */
interface Value
{
}

/**
 * @implements Value<int>
 */
final class IntValue implements Value
{
}

/**
 * @template T
 * @template TValue of Value<T>
 */
interface ValueProcessor
{
    /**
     * @param TValue $value
     * @return T
     */
    public function process(Value $value): mixed;
}

/**
 * @implements ValueProcessor<int, IntValue>
 */
final class IntValueProcessor implements ValueProcessor
{
    public function process(Value $value): mixed
    {
        return '';
    }
}
Psalm output (using commit 4eacb2f):

No issues!

@vudaltsov
Copy link
Contributor Author

Interestingly the problem disappears if I remove : mixed return type in IntValueProcessor::process.

https://psalm.dev/r/1a20f5a3a4

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/1a20f5a3a4
<?php

declare(strict_types=1);

/**
 * @template T
 */
interface Value
{
}

/**
 * @implements Value<int>
 */
final class IntValue implements Value
{
}

/**
 * @template T
 * @template TValue of Value<T>
 */
interface ValueProcessor
{
    /**
     * @param TValue $value
     * @return T
     */
    public function process(Value $value): mixed;
}

/**
 * @implements ValueProcessor<int, IntValue>
 */
final class IntValueProcessor implements ValueProcessor
{
    public function process(Value $value)
    {
        return '';
    }
}
Psalm output (using commit 4eacb2f):

ERROR: InvalidReturnStatement - 39:16 - The inferred type '''' does not match the declared return type 'int' for IntValueProcessor::process

ERROR: InvalidReturnType - 37:21 - The declared return type 'int' for IntValueProcessor::process is incorrect, got ''''

@vudaltsov
Copy link
Contributor Author

vudaltsov commented Feb 8, 2023

Regression occurred after #8926 was merged.

Commit da001c4 is the last one, when Psalm reports the problem (correct behavior).

@vudaltsov
Copy link
Contributor Author

Closing in favor of #9245 which has a simpler example.

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