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

Fix #3811 - allow more complex negations inside boolean expressions

This commit is contained in:
Brown 2020-07-13 21:31:58 -04:00
parent 931d35a703
commit 2399643472
3 changed files with 43 additions and 0 deletions

View File

@ -197,7 +197,12 @@ class AssertionFinder
throw new \UnexpectedValueException('Assertions should be set');
}
if (count($expr_assertions) !== 1) {
return [];
}
$if_types = \Psalm\Type\Algebra::negateTypes($expr_assertions);
return $if_types;
}

View File

@ -256,6 +256,17 @@ class Algebra
false
);
}
return self::negateFormula(
self::getFormula(
$object_id,
$conditional->expr,
$this_class_name,
$source,
$codebase,
!$inside_negation
)
);
}
if ($conditional instanceof PhpParser\Node\Expr\BinaryOp\Identical

View File

@ -1162,6 +1162,33 @@ class AssertAnnotationTest extends TestCase
allString($keys);
}',
],
'multipleAssertIfTrue' => [
'<?php
/**
* @param mixed $a
* @param mixed $b
* @psalm-assert-if-true string $a
* @psalm-assert-if-true string $b
*/
function assertAandBAreStrings($a, $b): bool {
if (!is_string($a)) { return false;}
if (!is_string($b)) { return false;}
return true;
}
/**
* @param mixed $a
* @param mixed $b
*/
function test($a, $b): string {
if (!assertAandBAreStrings($a, $b)) {
throw new \Exception();
}
return substr($a, 0, 1) . substr($b, 0, 1);
}'
],
];
}