1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Fix issue erasing nullability of boolean

This commit is contained in:
Matthew Brown 2018-06-17 13:47:31 -04:00
parent 2c245b0a08
commit d4107f9e5e
2 changed files with 18 additions and 6 deletions

View File

@ -229,6 +229,12 @@ class AssertionFinder
} else {
$if_types[$var_name] = [['falsy']];
}
} elseif ($var_type) {
$notif_types = self::getAssertions($base_conditional, $this_class_name, $source);
if (count($notif_types) === 1) {
$if_types = \Psalm\Type\Algebra::negateTypes($notif_types);
}
}
if ($var_type) {
@ -258,12 +264,6 @@ class AssertionFinder
}
}
}
$notif_types = self::getAssertions($base_conditional, $this_class_name, $source);
if (count($notif_types) === 1) {
$if_types = \Psalm\Type\Algebra::negateTypes($notif_types);
}
}
return $if_types;

View File

@ -456,6 +456,18 @@ class RedundantConditionTest extends TestCase
if ($s !== true ) {}
}',
],
'noRedundantConditionNullableBoolIsFalseOrTrue' => [
'<?php
function foo(?bool $s) : void {
if ($s === false ) {} elseif ($s === true) {}
}',
],
'noRedundantConditionNullableBoolIsTrueOrFalse' => [
'<?php
function foo(?bool $s) : void {
if ($s === true ) {} elseif ($s === false) {}
}',
],
];
}