Skip to content

[Regression] Inferred types #1126

Closed
phpactor/worse-reflection
#73

Description

@camilledejoye

I forgot that I had found a regression, I reproduced it today so I put an example here in order to not forget to fix it:

<?php

namespace Test;

interface Foo
{
}

class FooBar implements Foo
{
}

class Bar
{
    private Foo $foo;

    public function __construct(Foo $foo)
    {
        $this->foo = $foo;
    }

    public function foo(): void
    {
        if (!$this->foo instanceof FooBar) {
            return;
        }

        // $this is now inferred as FooBar
    }
}

It's all in the comment, kind of really annoying 😄

Activity

  1. dantleech commented on Nov 10, 2020

    @dantleech
    Collaborator

    Regression or bug? I don't think we did anything to change this behavior?

  2. camilledejoye commented on Nov 11, 2020

    @camilledejoye
    ContributorAuthor

    For me it's a regression, I don't remember ever having this problem (except the previous time I mentioned but I didn't created the ticket right away).

  3. dantleech commented on Nov 11, 2020

    @dantleech
    Collaborator

    AFAIK this would always been the case, we don't track property types currently: https://github.com/phpactor/worse-reflection/blob/360a923947ac2c4646e81ebd12fa2d2391c94830/lib/Core/Inference/FrameBuilder/InstanceOfWalker.php#L18 and it is wrongly seeing $this as the target.

    The whole inference thing is a bit of a mess.

  4. camilledejoye commented on Nov 11, 2020

    @camilledejoye
    ContributorAuthor

    I'm surprise I never had this issue before ><
    I will finishing with phpactor/indexer-extension#24 (comment) and try to fix this one next

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions