1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Fix #694 - remove descendent vars when possibly reassigning

This commit is contained in:
Matthew Brown 2018-04-24 21:02:07 -04:00
parent 2a890aa6ce
commit 3e7e1b3020
3 changed files with 33 additions and 7 deletions

View File

@ -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;
}
}
}

View File

@ -998,6 +998,15 @@ class LoopScopeTest extends TestCase
}
}',
],
'noRedundantConditionAfterArrayAssignment' => [
'<?php
$data = ["a" => false];
while (!$data["a"]) {
if (rand() % 2 > 0) {
$data = ["a" => true];
}
}',
],
];
}

View File

@ -22,8 +22,14 @@ class TestCase extends BaseTestCase
public static function setUpBeforeClass()
{
ini_set('memory_limit', '-1');
define('PSALM_VERSION', '2.0.0');
define('PHP_PARSER_VERSION', '4.0.0');
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;