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:
parent
f2a70fef85
commit
09eb316a9c
@ -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);
|
||||
}
|
||||
|
@ -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);',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user