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

False positive errors when using class-string<static> inside trait #2952

Closed
gharlan opened this issue Mar 9, 2020 · 2 comments
Closed

False positive errors when using class-string<static> inside trait #2952

gharlan opened this issue Mar 9, 2020 · 2 comments

Comments

@gharlan
Copy link
Contributor

gharlan commented Mar 9, 2020

https://psalm.dev/r/bc5e4d038b

The errors seem to be new in dev-master, I do not get them with last release.
They only appear in the second class using the trait, not in the first one.

@psalm-github-bot
Copy link

I found these snippets:

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

trait Factory
{
    /** @return class-string<static> */
    public static function getFactoryClass()
    {
        return '...';
    }
}

class A
{
    use Factory;
    
    public static function factory(): self
    {
        $class = static::getFactoryClass();
        return new $class;
    }
}

class B
{
    use Factory;
    
    public static function factory(): self
    {
        $class = static::getFactoryClass();
        return new $class;
    }
}
Psalm output (using commit a5672db):

INFO: MoreSpecificReturnType - 5:17 - The declared return type 'class-string<A>' for Factory::getFactoryClass is more specific than the inferred return type 'string(...)'

ERROR: InvalidReturnStatement - 30:16 - The inferred type 'A' does not match the declared return type 'B' for B::factory

ERROR: InvalidReturnType - 27:39 - The declared return type 'B' for B::factory is incorrect, got 'A'

@muglug muglug closed this as completed in 0cfe565 Mar 9, 2020
@muglug
Copy link
Collaborator

muglug commented Mar 9, 2020

Thanks!

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

2 participants