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

No warnings for if-else with instanceof chains #370

Closed
quasilyte opened this issue Mar 20, 2020 · 0 comments · Fixed by #1038
Closed

No warnings for if-else with instanceof chains #370

quasilyte opened this issue Mar 20, 2020 · 0 comments · Fixed by #1038
Labels
bug Something isn't working

Comments

@quasilyte
Copy link
Contributor

Code Example

<?php

class Fooo1 { public $a; }
class Fooo2 { public $b; }

global $globf;

if ($globf instanceof Fooo1) {
    echo $globf->a;
} elseif ($globf instanceof Fooo2) {
    echo $globf->a; // <-- no warnings (bad)
    echo $globf->b;
} else {
    echo $globf->a; // <-- no warnings (bad)
}

Actual Behavior

No warnings.

Expected Behavior

Warning for undefined property a.

The problem is, noverify assigns \Fooo1|\Fooo2 type for $globf inside a second if body, so we can access both Fooo1 and Fooo2 members there.

quasilyte added a commit that referenced this issue Mar 20, 2020
This change attempts to improve handleIf behavior.

We introduce implicit kind of vars to express automatically
defined vars that can be handled in a special way.

andWalker.varsToDelete are removed because we're running
all branches in a separate block contexts. No extra
cleanup is required.

Changed code requires to evaluate if statement condition
separately, so we can get variables defined inside it
into the parent block context.
assignWalker type does that.

Fixes #369
Fixes #363
Fixes #370

Signed-off-by: Iskander Sharipov <quasilyte@gmail.com>
quasilyte added a commit that referenced this issue Mar 20, 2020
This change attempts to improve handleIf behavior.

We introduce implicit kind of vars to express automatically
defined vars that can be handled in a special way.

andWalker.varsToDelete are removed because we're running
all branches in a separate block contexts. No extra
cleanup is required.

Changed code requires to evaluate if statement condition
separately, so we can get variables defined inside it
into the parent block context.
assignWalker type does that.

Fixes #369
Fixes #363
Fixes #370

Signed-off-by: Iskander Sharipov <quasilyte@gmail.com>
@i582 i582 added the bug Something isn't working label Jul 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants