Skip to content

Fixed false-positive with by-ref parameters and array-functions #4036

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

Merged
merged 10 commits into from
May 31, 2025

Conversation

staabm
Copy link
Contributor

@staabm staabm commented May 31, 2025

Copy link
Member

@ondrejmirtes ondrejmirtes left a comment

Choose a reason for hiding this comment

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

Maybe the right scope needs to be used also below in more VariableAssignNode instances? Try writing a failing test first.

Copy link
Member

@ondrejmirtes ondrejmirtes left a comment

Choose a reason for hiding this comment

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

Also:

  1. new PropertyAssignNode on line 5630
  2. dtto on line 5676
  3. dtto on line 5719
  4. dtto on line 5750

@ondrejmirtes
Copy link
Member

You can look at other new VariableAssignNode and PropertyAssignNode. Maybe there's more.

@staabm
Copy link
Contributor Author

staabm commented May 31, 2025

not sure how to test the ExistingArrayDimFetch variant

if ($var instanceof Variable && is_string($var->name)) {
$nodeCallback(new VariableAssignNode($var, $assignedPropertyExpr), $scope);
$scope = $scope->assignVariable($var->name, $valueToWrite, $nativeValueToWrite, TrinaryLogic::createYes());
} else {
if ($var instanceof PropertyFetch || $var instanceof StaticPropertyFetch) {
$nodeCallback(new PropertyAssignNode($var, $assignedPropertyExpr, $isAssignOp), $scope);
}
$scope = $scope->assignExpression(
$var,
$valueToWrite,
$nativeValueToWrite,
);
}

@ondrejmirtes
Copy link
Member

I don't think the expr is processed and scope changed for this one.

@ondrejmirtes
Copy link
Member

Looks like quite a few more bugs were fixed! https://github.com/phpstan/phpstan-src/actions/runs/15362052666

@staabm staabm marked this pull request as ready for review May 31, 2025 09:23
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

@ondrejmirtes ondrejmirtes merged commit cfa0299 into phpstan:2.1.x May 31, 2025
419 of 421 checks passed
@ondrejmirtes
Copy link
Member

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants