-
Notifications
You must be signed in to change notification settings - Fork 555
Fix phpstan/phpstan#14333: Setting an array key doesn't update a reference #5257
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
15
commits into
phpstan:2.1.x
Choose a base branch
from
phpstan-bot:create-pull-request/patch-bsc1yhl
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.
+205
−18
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
59ca979
Fix phpstan/phpstan#14333: Setting an array key doesn't update a refe…
VincentLanglet 85e52c5
Add test for nested array reference tracking limitation
phpstan-bot 40bab7a
Skip implicit-key by-ref tracking when index is uncertain due to non-…
phpstan-bot 1791c8b
Simplify
VincentLanglet 9ba6411
Fix
VincentLanglet 2407895
Implement nested array reference tracking
phpstan-bot 5aee21a
Simplify
VincentLanglet f6a987e
Add comment explaining why implicitIndex is set to null for non-const…
phpstan-bot f1f6eb7
Move intertwined ref preservation from assignVariable to invalidateEx…
phpstan-bot 88ea889
Move intertwined ref preservation condition into shouldInvalidateExpr…
phpstan-bot 3200c9f
Simplify
VincentLanglet c5824eb
Rename and simplify isDimFetchPathReachable to absorb nested check
phpstan-bot 85b5b5f
Add failing test
VincentLanglet 94a3bd9
Fix lint
VincentLanglet f0ba82a
Prevent circular back-propagation of intertwined refs during variable…
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
Some comments aren't visible on the classic Files Changed page.
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
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,82 @@ | ||
| <?php declare(strict_types = 1); | ||
|
|
||
| namespace Bug14333; | ||
|
|
||
| use function PHPStan\Testing\assertType; | ||
|
|
||
| function testByRefInArrayWithKey(): void | ||
| { | ||
| $a = 'hello'; | ||
| assertType("'hello'", $a); | ||
|
|
||
| $b = ['key' => &$a]; | ||
| assertType("'hello'", $a); | ||
|
|
||
| $b['key'] = 42; | ||
| assertType('42', $a); | ||
| } | ||
|
|
||
| function testMultipleByRefInArray(): void | ||
| { | ||
| $a = 1; | ||
| $c = 'test'; | ||
|
|
||
| $b = [&$a, 'normal', &$c]; | ||
| assertType('1', $a); | ||
| assertType("'test'", $c); | ||
|
|
||
| $b[0] = 2; | ||
| $b[1] = 'foo'; | ||
| $b[2] = 'bar'; | ||
|
|
||
| assertType('2', $a); | ||
| assertType("'bar'", $c); | ||
| } | ||
|
|
||
| function testNonConstantKeyBreaksImplicitIndex(int $key): void | ||
| { | ||
| $a = 1; | ||
| $c = 'test'; | ||
|
|
||
| $b = [$key => 'x', &$a, &$c]; | ||
| assertType('1', $a); | ||
| assertType("'test'", $c); | ||
|
|
||
| // Since $key is non-constant, we don't know the implicit indices of &$a and &$c | ||
| // so we can't track the reference propagation | ||
| $b[0] = 2; | ||
| assertType('1', $a); | ||
| } | ||
|
|
||
| function testNested(): void | ||
| { | ||
| $a = 1; | ||
|
|
||
| $b = [[&$a]]; | ||
| assertType('1', $a); | ||
|
|
||
| $b[0][0] = 2; | ||
|
|
||
| assertType('2', $a); | ||
|
|
||
| $b[0] = []; | ||
|
|
||
| assertType('2', $a); | ||
|
|
||
| $b[0][0] = 3; | ||
|
|
||
| assertType('2', $a); | ||
| } | ||
|
|
||
| function foo(array &$a): void {} | ||
|
|
||
| function testFunctionCall() { | ||
| $b = 1; | ||
|
|
||
| $c = [&$b]; | ||
| assertType('array{1}', $c); | ||
|
|
||
| foo($c); | ||
| assertType('array', $c); | ||
| assertType('mixed', $b); | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.