1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Fix #346 by making a change in from_docblock invalidate clauses

This commit is contained in:
Matt Brown 2017-11-28 17:27:19 -05:00
parent 33f003f427
commit 252fa8da78
2 changed files with 21 additions and 2 deletions

View File

@ -87,6 +87,7 @@ class TypeChecker
$before_adjustment = (string)$result_type;
$failed_reconciliation = false;
$from_docblock = $result_type && $result_type->from_docblock;
foreach ($new_type_parts as $new_type_part) {
$new_type_part_parts = explode('|', $new_type_part);
@ -125,7 +126,9 @@ class TypeChecker
continue;
}
if ((string)$result_type !== $before_adjustment) {
if ((string)$result_type !== $before_adjustment
|| $result_type->from_docblock !== $from_docblock
) {
$changed_var_ids[] = $key;
}
@ -186,7 +189,7 @@ class TypeChecker
return Type::parseString($new_var_type);
}
return $new_var_type === '!falsy' ? Type::getMixed() : null;
return $new_var_type === '!falsy' ? Type::getMixed() : false;
}
if ($new_var_type === 'mixed' && $existing_var_type->isMixed()) {

View File

@ -32,6 +32,22 @@ class RedundantConditionTest extends TestCase
],
'error_levels' => ['RedundantCondition'],
],
'byrefNoRedundantCondition' => [
'<?php
/**
* @param int $min ref
* @param int $other
*/
function testmin(&$min, int $other) : void {
if (is_null($min)) {
$min = 3;
} elseif (!is_int($min)) {
$min = 5;
} elseif ($min < $other) {
$min = $other;
}
}',
],
];
}