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

Variable type incorrectly resolves to never after some loops #3117

Open
lkrms opened this issue Nov 19, 2024 · 0 comments
Open

Variable type incorrectly resolves to never after some loops #3117

lkrms opened this issue Nov 19, 2024 · 0 comments
Labels

Comments

@lkrms
Copy link

lkrms commented Nov 19, 2024

Describe the bug

In while loops that combine a test for an object's truthiness with another condition, Intelephense incorrectly determines that the variable's type is subsequently never, even though the second part of the expression may have been the one that failed.

To Reproduce

Here's a minimal example. After the loop, Intelephense treats $foo as never.

<?php

class Foo
{
    public int $Id;
    public ?Foo $Next;
}

function bar(Foo $foo)
{
    while ($foo && $foo->Id === -1) {
        $foo = $foo->Next;
    }
    // $foo is `never` but should be `Foo|null`, and Intellisense doesn't work
    if ($foo) {
        echo $foo->Id;
    }
}

Platform and version

v1.12.6 on macOS and Linux

@bmewburn bmewburn added the bug label Nov 19, 2024
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