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

Erroneous return type matched when using multiple interfaces using `self` as return type #2102

Open
Ocramius opened this issue Sep 6, 2019 · 8 comments

Comments

@Ocramius
Copy link
Contributor

Ocramius commented Sep 6, 2019

See https://psalm.dev/r/8170d89c39:

<?php

interface Id {}
interface Foo
{
    public function id() : Id;
}

class ImplementsFoo implements Foo, Id
{
     public function id() : self
     {
          return $this;
     }
}

Reports:

Psalm output (using commit ae2c671):

ERROR: MethodSignatureMismatch - 9:7 - Method ImplementsFoo::id with return type 'ImplementsFoo' is different to return type 'Id' of inherited method Foo::id

Even simpler in https://psalm.dev/r/494e02869f:

Psalm output (using commit ae2c671):

ERROR: MethodSignatureMismatch - 8:7 - Method ImplementsFoo::id with return type 'ImplementsFoo' is different to return type 'Foo' of inherited method Foo::id

Reports:

<?php

interface Foo
{
    public function id() : self;
}

class ImplementsFoo implements Foo
{
     public function id() : self
     {
          return $this;
     }
}

Related: sebastianbergmann/phpunit#3120

Ocramius added a commit to Ocramius/phpunit that referenced this issue Sep 6, 2019
… type mismatch as false positive

The method `InvocationMocker#will()` is LSP-compliant with the parent
types, but a bug in psalm reports it as a false positive.

Ref: vimeo/psalm#2102
@Ocramius

This comment has been minimized.

Copy link
Contributor Author

Ocramius commented Sep 6, 2019

Ah... this is a PHP 7.4 thing, my bad.

Working on bleeding edge spoiled me.

sebastianbergmann added a commit to sebastianbergmann/phpunit that referenced this issue Sep 6, 2019
… false positive

The method `InvocationMocker#will()` is LSP-compliant with the parent
types, but a bug in psalm reports it as a false positive.

Ref: vimeo/psalm#2102
@muglug muglug added the PHP 7.4 label Sep 6, 2019
@muglug

This comment has been minimized.

Copy link
Member

muglug commented Sep 6, 2019

Yeah I'll disable this when Psalm detects it's running on 7.4

@muglug

This comment has been minimized.

Copy link
Member

muglug commented Sep 6, 2019

I have other features (e.g. arrow functions) ready to ship, but I don't want to bump the upstream dependency (nikic/php-parser) version until necessary, once 7.4 is publicly available

@zmitic

This comment has been minimized.

Copy link

zmitic commented Oct 22, 2019

@muglug Can you put arrow functions support in master or fork? I would really like to get rid of errors like this:

image

@Ocramius

This comment has been minimized.

Copy link
Contributor Author

Ocramius commented Oct 22, 2019

@zmitic a bit of patience: PHP 7.4 isn't even out yet :-)

@zmitic

This comment has been minimized.

Copy link

zmitic commented Oct 22, 2019

@Ocramius I know, I know... but I love it 😄

Above example is just one small thing. More complex are coming tomorrow when I put entity accessors: https://github.com/hitechcoding/strict-form-mapper-bundle/blob/master/docs/accessors.md

Arrow functions really makes these things easier.

@muglug

This comment has been minimized.

Copy link
Member

muglug commented Oct 23, 2019

@zmitic the branch (arrow-functions) already exists, I've just rebased it on top of latest master.

I'll add Psalm compatibility about a week before PHP's 7.4 release date.

@zmitic

This comment has been minimized.

Copy link

zmitic commented Oct 23, 2019

@muglug Thank you, a lot! My errors are gone now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.