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

TypeDoesNotContainxy after on isset after unset in a loop #4995

Open
blizzz opened this issue Jan 12, 2021 · 2 comments
Open

TypeDoesNotContainxy after on isset after unset in a loop #4995

blizzz opened this issue Jan 12, 2021 · 2 comments
Labels

Comments

@blizzz
Copy link

blizzz commented Jan 12, 2021

Minimal example: https://psalm.dev/r/cd3ebd7a1c

If there is a variable containing an instance of something that might get unset in a loop, Psalm complains when checking with isset().

@psalm-github-bot
Copy link

I found these snippets:

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

class A { 
    function noop(): void {
        sleep(0);
    }
}

$a = new A();
while(true) {
    if(!isset($a)) {
        exit(0);
    }
    $a->noop();
    unset($a);
}
Psalm output (using commit 1afce4d):

ERROR: TypeDoesNotContainNull - 11:9 - Cannot resolve types for $a - A does not contain null

@orklah
Copy link
Collaborator

orklah commented Oct 14, 2021

Note for whoever will work on this in the future: TMixed takes an optional parameter inside_loop. This is used to allow overriding TMixed when it's generate by calling isset() on an empty array. We probably need to generate the same TMixed with inside loop when we encounter an unset instead of setting the variable to null. The loop may automatically recover from this

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