Skip to content

Assignments should void dependant inferences#96

Merged
ondrejmirtes merged 2 commits intophpstan:masterfrom
cs278:issue-2822
Jan 11, 2020
Merged

Assignments should void dependant inferences#96
ondrejmirtes merged 2 commits intophpstan:masterfrom
cs278:issue-2822

Conversation

@cs278
Copy link
Copy Markdown
Contributor

@cs278 cs278 commented Jan 11, 2020

@ondrejmirtes
Copy link
Copy Markdown
Member

Hi, can you sum up in your own words what was wrong with the previous code and why does your work?

@cs278
Copy link
Copy Markdown
Contributor Author

cs278 commented Jan 11, 2020

/** @param int[] $input */
function (array $input) {
    $i = 0;
    // $input[$i] is int
    \assert($input[$i] === 1);
    // $input[$i] is 1
    $i++;
    // $input[$i] is 1 (without this PR)
    // $input[$i] is int (with this PR)
};

PHPStan was only extracting the first variable referenced so in the string $input[$i] it would only find $input which is not being assigned so is not unset. My change results in both $input and $i being found, $i is being assigned so the known value of $input[$i] is unset.

@ondrejmirtes
Copy link
Copy Markdown
Member

Of course, nice find! Thank you.

@ondrejmirtes ondrejmirtes merged commit e81d732 into phpstan:master Jan 11, 2020
@cs278 cs278 deleted the issue-2822 branch January 11, 2020 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

False positive: Strict comparison using === between ... will always evaluate to false.

2 participants