mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
Refine isset checks
This commit is contained in:
parent
54a31f8cff
commit
e8618371fb
@ -96,16 +96,7 @@ class IfAnalyzer
|
||||
$mixed_var_ids = [];
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
if ($type->hasMixed() && isset($context->vars_in_scope[$var_id])) {
|
||||
$mixed_var_ids[] = $var_id;
|
||||
}
|
||||
}
|
||||
|
@ -358,6 +358,27 @@ class AssertTest extends TestCase
|
||||
if ($c && rand(0, 1)) {}
|
||||
}'
|
||||
],
|
||||
'assertMixedOffsetExists' => [
|
||||
'<?php
|
||||
class A {
|
||||
/** @var mixed */
|
||||
private $arr;
|
||||
|
||||
/**
|
||||
* @psalm-suppress MixedArrayAccess
|
||||
* @psalm-suppress MixedReturnStatement
|
||||
* @psalm-suppress MixedInferredReturnType
|
||||
*/
|
||||
public function foo() : stdClass {
|
||||
if (isset($this->arr[0])) {
|
||||
return $this->arr[0];
|
||||
}
|
||||
|
||||
$this->arr[0] = new stdClass;
|
||||
return $this->arr[0];
|
||||
}
|
||||
}'
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user