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

ImplementedReturnTypeMismatch on method implemented in non-template trait and declared abstract in a templated trait #6973

Closed
ptomulik opened this issue Nov 22, 2021 · 1 comment

Comments

@ptomulik
Copy link
Contributor

ptomulik commented Nov 22, 2021

https://psalm.dev/r/97a5b80220

It's not a duplicate of #6937. The #6963 does not fix this, but I think I have a fix for it.

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/97a5b80220
<?php
trait ImplementorTrait {
    /** @var int */
    private $value;

    public function getValue(): int {
        return $this->value;
    }
}

/** @psalm-template T */
trait GuideTrait {
    /** @psalm-return T */
    abstract public function getValue();
}

class Test {
    use ImplementorTrait;

    /** @template-use GuideTrait<int> */
    use GuideTrait;

    public function __construct() {
        $this->value = 123;
    }
}
Psalm output (using commit eca56c0):

ERROR: ImplementedReturnTypeMismatch - 6:33 - The inherited return type 'T:GuideTrait as mixed' for GuideTrait::getValue is different to the implemented return type for ImplementorTrait::getvalue 'int'

ptomulik added a commit to ptomulik/psalm that referenced this issue Nov 22, 2021
ptomulik added a commit to ptomulik/psalm that referenced this issue Nov 22, 2021
@ptomulik ptomulik changed the title is:issue is:open ImplementedReturnTypeMismatch on method implemented in non-template trait and declared abstract in a templated trait ImplementedReturnTypeMismatch on method implemented in non-template trait and declared abstract in a templated trait Nov 23, 2021
ptomulik added a commit to ptomulik/psalm that referenced this issue Nov 23, 2021
@orklah orklah closed this as completed in dac8c98 Nov 23, 2021
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