forked from vimeo/psalm
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve handling of unsupported references (fixes vimeo#8018).
- Loading branch information
1 parent
b46fb14
commit 31b4dce
Showing
9 changed files
with
150 additions
and
72 deletions.
There are no files selected for viewing
This file contains 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 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 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,34 @@ | ||
# UnsupportedReferenceUsage | ||
|
||
Emitted when Psalm encounters a reference that it is not currently able to track (for instance a reference to an array | ||
offset of an array offset: `$foo = &$bar[$baz[0]]`). When an unsupported reference is encountered, Psalm will issue this | ||
warning and treat the variable as though it wasn't actually a reference. | ||
|
||
## How to fix | ||
|
||
This can sometimes be fixed by using a temporary variable: | ||
|
||
```php | ||
<?php | ||
|
||
/** @var non-empty-list<int> */ | ||
$bar = [1, 2, 3]; | ||
/** @var non-empty-list<int> */ | ||
$baz = [1, 2, 3]; | ||
|
||
$foo = &$bar[$baz[0]]; | ||
``` | ||
|
||
can be turned into | ||
|
||
```php | ||
<?php | ||
|
||
/** @var non-empty-list<int> */ | ||
$bar = [1, 2, 3]; | ||
/** @var non-empty-list<int> */ | ||
$baz = [1, 2, 3]; | ||
|
||
$offset = $baz[0]; | ||
$foo = &$bar[$offset]; | ||
``` |
This file contains 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 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 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 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 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,9 @@ | ||
<?php | ||
|
||
namespace Psalm\Issue; | ||
|
||
final class UnsupportedReferenceUsage extends CodeIssue | ||
{ | ||
public const ERROR_LEVEL = 2; | ||
public const SHORTCODE = 312; | ||
} |
This file contains 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