mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
Fix #694 - remove descendent vars when possibly reassigning
This commit is contained in:
parent
2a890aa6ce
commit
3e7e1b3020
@ -460,12 +460,23 @@ class IfChecker
|
||||
}
|
||||
|
||||
if ($if_scope->possibly_redefined_vars) {
|
||||
foreach ($if_scope->possibly_redefined_vars as $var => $type) {
|
||||
if ($context->hasVariable($var) &&
|
||||
!$type->failed_reconciliation &&
|
||||
!isset($if_scope->updated_vars[$var])
|
||||
foreach ($if_scope->possibly_redefined_vars as $var_id => $type) {
|
||||
if ($context->hasVariable($var_id)) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($if_scope->possibly_redefined_vars as $var_id => $type) {
|
||||
if ($context->hasVariable($var_id)
|
||||
&& !$type->failed_reconciliation
|
||||
&& !isset($if_scope->updated_vars[$var_id])
|
||||
) {
|
||||
$context->vars_in_scope[$var] = Type::combineUnionTypes($context->vars_in_scope[$var], $type);
|
||||
$combined_type = Type::combineUnionTypes(
|
||||
$context->vars_in_scope[$var_id],
|
||||
$type
|
||||
);
|
||||
$context->removeDescendents($var_id, $combined_type);
|
||||
$context->vars_in_scope[$var_id] = $combined_type;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -998,6 +998,15 @@ class LoopScopeTest extends TestCase
|
||||
}
|
||||
}',
|
||||
],
|
||||
'noRedundantConditionAfterArrayAssignment' => [
|
||||
'<?php
|
||||
$data = ["a" => false];
|
||||
while (!$data["a"]) {
|
||||
if (rand() % 2 > 0) {
|
||||
$data = ["a" => true];
|
||||
}
|
||||
}',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -22,8 +22,14 @@ class TestCase extends BaseTestCase
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
ini_set('memory_limit', '-1');
|
||||
|
||||
if (!defined('PSALM_VERSION')) {
|
||||
define('PSALM_VERSION', '2.0.0');
|
||||
}
|
||||
|
||||
if (!defined('PHP_PARSER_VERSION')) {
|
||||
define('PHP_PARSER_VERSION', '4.0.0');
|
||||
}
|
||||
|
||||
parent::setUpBeforeClass();
|
||||
self::$src_dir_path = getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR;
|
||||
|
Loading…
Reference in New Issue
Block a user