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

Fix #755 - add support for inferring explicit true checks

This commit is contained in:
Matthew Brown 2018-05-19 00:41:07 -04:00
parent f2a70fef85
commit 09eb316a9c
2 changed files with 16 additions and 1 deletions

View File

@ -184,7 +184,11 @@ class AssertionFinder
);
if ($var_name) {
$if_types[$var_name] = '!falsy';
if ($conditional instanceof PhpParser\Node\Expr\BinaryOp\Identical) {
$if_types[$var_name] = 'true';
} else {
$if_types[$var_name] = '!falsy';
}
} else {
return self::getAssertions($base_conditional, $this_class_name, $source);
}

View File

@ -856,6 +856,17 @@ class TypeReconciliationTest extends TestCase
'$doc[\'s\'][\'t\']' => 'array<int, string>',
],
],
'removeTrue' => [
'<?php
$a = rand(0, 1) ? new stdClass : true;
if ($a === true) {
exit;
}
function takesStdClass(stdClass $s) : void {}
takesStdClass($a);',
],
];
}