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 return value is not detected for methods with a template return type since 5.3 #9245

Closed
vudaltsov opened this issue Feb 8, 2023 · 2 comments · Fixed by #9865
Closed

Comments

@vudaltsov
Copy link
Contributor

This code has an error on line 23 (should return int, not string).

https://psalm.dev/r/aa26301af0

Removing the mixed return type fixes the issue: https://psalm.dev/r/6bf5cdea8a.

Regression occurred in #8926.

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

@psalm-github-bot
Copy link

I found these snippets:

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

declare(strict_types=1);

/**
 * @template T
 */
interface I
{
    /**
     * @return T
     */
    public function process(): mixed;
}

/**
 * @implements I<int>
 */
final class B implements I
{
    public function process(): mixed
    {
        return '';
    }
}
Psalm output (using commit 4eacb2f):

No issues!
https://psalm.dev/r/6bf5cdea8a
<?php

declare(strict_types=1);

/**
 * @template T
 */
interface I
{
    /**
     * @return T
     */
    public function process();
}

/**
 * @implements I<int>
 */
final class B implements I
{
    public function process()
    {
        return '';
    }
}
Psalm output (using commit 4eacb2f):

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

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

@orklah
Copy link
Collaborator

orklah commented Feb 8, 2023

@danog could you take a look please?

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

Successfully merging a pull request may close this issue.

2 participants