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

Static return type error #5244

Closed
vudaltsov opened this issue Feb 17, 2021 · 2 comments
Closed

Static return type error #5244

vudaltsov opened this issue Feb 17, 2021 · 2 comments
Labels

Comments

@vudaltsov
Copy link
Contributor

This is another case around of #5070, I guess.

https://psalm.dev/r/3e50a930e7

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/3e50a930e7
<?php

abstract class A
{
    abstract public static function create(): static;
}

final class X extends A
{
    public static function create(): static
    {
        return new self();
    }
}

final class Z extends A
{
    /**
     * @psalm-return static
     */
    public static function create(): static
    {
        return new self();
    }
}
Psalm output (using commit 9d6d391):

INFO: LessSpecificReturnStatement - 12:16 - The type 'X' is more general than the declared return type 'X&static' for X::create

INFO: MoreSpecificReturnType - 10:38 - The declared return type 'X&static' for X::create is more specific than the inferred return type 'X'

@weirdan
Copy link
Collaborator

weirdan commented Feb 17, 2021

It seem to affect final classes only, even with return static.

@weirdan weirdan added the bug label Feb 17, 2021
@muglug muglug closed this as completed in def7326 Feb 24, 2021
This was referenced Mar 15, 2021
This was referenced Mar 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants