1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Fix #3045 - ignore mixed assignments to variables named $_ (#3211)

This commit is contained in:
Fabien Villepinte 2020-04-22 02:18:38 +02:00 committed by GitHub
parent 16fa208a60
commit a93bf28532
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 1 deletions

View File

@ -32,6 +32,7 @@ use Psalm\Type;
use function is_string;
use function strpos;
use function strtolower;
use function substr;
/**
* @internal
@ -342,6 +343,7 @@ class AssignmentAnalyzer
if (!$assign_var instanceof PhpParser\Node\Expr\PropertyFetch
&& !strpos($root_var_id ?? '', '->')
&& !$comment_type
&& substr($var_id ?? '', 0, 2) !== '$_'
) {
if (IssueBuffer::accepts(
new MixedAssignment(

View File

@ -787,6 +787,17 @@ class ReturnTypeTest extends TestCase
'$res' => 'iterable<mixed, string>',
],
],
'mixedAssignmentWithUnderscore' => [
'<?php
$gen = (function (): Generator {
yield 1 => \'a\';
yield 2 => \'b\';
})();
foreach ($gen as $k => $_) {
echo "$k\n";
}'
],
];
}

View File

@ -674,7 +674,6 @@ class UnusedCodeTest extends TestCase
$items = new IterableResult();
/** @psalm-suppress MixedAssignment */
foreach ($items as $_item) {}'
],
'usedThroughNewClassStringOfBase' => [