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

Be more scrupulous about mixed vars

This commit is contained in:
Matthew Brown 2019-10-17 00:29:51 -04:00
parent 29902c8b99
commit 54a31f8cff
2 changed files with 32 additions and 0 deletions

View File

@ -97,6 +97,15 @@ class IfAnalyzer
foreach ($if_context->vars_in_scope as $var_id => $type) {
if ($type->hasMixed()) {
foreach ($if_context->vars_in_scope as $alt_var_id => $alt_type) {
if ($alt_var_id !== $alt_type
&& preg_match('/^' . preg_quote($alt_var_id, '/') . '(\[|-)/', $var_id)
&& !$alt_type->hasMixed()
) {
continue 2;
}
}
$mixed_var_ids[] = $var_id;
}
}

View File

@ -159,6 +159,29 @@ class ArrayAccessTest extends TestCase
$this->analyzeFile('somefile.php', new \Psalm\Context());
}
public function testNoIssueAfterManyIssets() : void
{
\Psalm\Config::getInstance()->ensure_array_int_offsets_exist = true;
$this->addFile(
'somefile.php',
'<?php
/**
* @return mixed
*/
function f(array $a) {
if (isset($a[1])
&& is_array($a[1])
&& isset($a[1][2])
) {
return $a[1][2];
}
}'
);
$this->analyzeFile('somefile.php', new \Psalm\Context());
}
/**
* @return void
*/