Skip to content

fix: FP variable might not be defined when in while and try-catch#671

Closed
ishan-deepsource wants to merge 4 commits intophpstan:masterfrom
ishan-deepsource:bug-5477
Closed

fix: FP variable might not be defined when in while and try-catch#671
ishan-deepsource wants to merge 4 commits intophpstan:masterfrom
ishan-deepsource:bug-5477

Conversation

@ishan-deepsource
Copy link

Signed-off-by: Ishan Vyas <ishan@deepsource.io>
Signed-off-by: Ishan Vyas <ishan@deepsource.io>
$branchScopeResult = $this->processStmtNodes($stmt, $stmt->stmts, $scope, $nodeCallback);
$branchScope = $branchScopeResult->getScope();
$finalScope = $branchScopeResult->isAlwaysTerminating() ? null : $branchScope;
$finalScope = $branchScopeResult->getScope()->mergeWith($finalScope);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me it looks like you're merging $branchScope with $branchScope or null. Are you sure?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I'm merging $branchScopeResult's $finalScope with $finalScope. This is the only way I could think of fixing this issue, is it proper?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might be right but I might be blind, but what I see is:

$branchScope = $branchScopeResult->getScope();
$finalScope = $branchScopeResult->isAlwaysTerminating() ? null : $branchScope;
$finalScope = $branchScopeResult->getScope()->mergeWith($finalScope);

Which can be rewritten as:

$branchScope = $branchScopeResult->getScope();
$finalScope = $branchScopeResult->isAlwaysTerminating() ? null : $branchScope;
$finalScope = $branchScope->mergeWith($finalScope); // $finalScope from previous line is null or $branchScope
// therefore you're doing either $branchScope->mergeWith($branchScope) or $branchScope->mergeWith(null)

Can you oppose what I see? :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you're right. Pushed latest changes, in this case $finalScope is null, so in order to fix this assigning $branchScope's scope to $finalScope.

Signed-off-by: Ishan Vyas <ishan@deepsource.io>
Signed-off-by: Ishan Vyas <ishan@deepsource.io>
@ondrejmirtes
Copy link
Member

Still too many build failures. Feel free to start fresh on top of latest master in a new PR, thanks.

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 - variable might not be define when while(true) and try-catch is involved

2 participants