-
Notifications
You must be signed in to change notification settings - Fork 555
Fix phpstan/phpstan#14275: Variable passed by reference are not updated #5217
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
Open
phpstan-bot
wants to merge
7
commits into
phpstan:2.1.x
Choose a base branch
from
phpstan-bot:create-pull-request/patch-qqhkbas
base: 2.1.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+116
−2
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4f744d6
Fix phpstan/phpstan#14275: Propagate type changes through variable re…
VincentLanglet a7f79ac
Add regression test for phpstan/phpstan#8056
phpstan-bot 9ac8874
Re-register intertwined variable entries after propagation for subseq…
phpstan-bot 504414a
Fix reference type propagation for subsequent assignments
phpstan-bot e89130e
Simplify reference propagation: prevent invalidation instead of re-re…
phpstan-bot fc6623f
Fix reference propagation to use chain tracking instead of boolean flag
phpstan-bot 1029763
Add rule test for bug 8056 to verify no false positive "Empty array p…
phpstan-bot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| <?php declare(strict_types = 1); | ||
|
|
||
| namespace Bug14275; | ||
|
|
||
| use function PHPStan\Testing\assertType; | ||
|
|
||
| // Basic reference: modifying $b should update $a | ||
| $a = []; | ||
| $b = &$a; | ||
|
|
||
| $b[0] = 1; | ||
| assertType('array{1}', $a); | ||
| assertType('array{1}', $b); | ||
|
|
||
| // Reference with scalar reassignment | ||
| $c = 1; | ||
| $d = &$c; | ||
| $d = 2; | ||
| assertType('2', $c); | ||
| assertType('2', $d); | ||
|
|
||
| // Reference with different type reassignment | ||
| $e = 'hello'; | ||
| $f = &$e; | ||
| $f = 42; | ||
| assertType('42', $e); | ||
| assertType('42', $f); | ||
|
|
||
| // Subsequent assignments should continue propagating | ||
| $e = 22; | ||
| assertType('22', $e); | ||
| assertType('22', $f); | ||
|
|
||
| $f = 33; | ||
| assertType('33', $e); | ||
| assertType('33', $f); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| <?php declare(strict_types = 1); | ||
|
|
||
| namespace Bug8056; | ||
|
|
||
| use function PHPStan\Testing\assertType; | ||
|
|
||
| $array = []; | ||
| $tmp = &$array; | ||
| $tmp[] = 'foo'; | ||
|
|
||
| assertType("array{'foo'}", $array); | ||
| assertType("array{'foo'}", $tmp); | ||
|
|
||
| foreach ($array as $i) { | ||
| assertType("'foo'", $i); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <?php declare(strict_types = 1); | ||
|
|
||
| namespace Bug8056Rule; | ||
|
|
||
| $array = []; | ||
| $tmp = &$array; | ||
| $tmp[] = 'foo'; | ||
|
|
||
| foreach ($array as $i) { | ||
|
|
||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bug 8056 was about a false positive with the error "Empty array passed to foreach.".
we should have a rule-test which verifies this false positive error no longer is emitted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Added a rule test (
testBug8056) inDeadForeachRuleTestwith a test data file that verifies the "Empty array passed to foreach" false positive is no longer emitted when iterating over an array that was modified through a reference variable. The test passes successfully.