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:
parent
29902c8b99
commit
54a31f8cff
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user