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

Fix #5685 - properly negate complex conditionals

This commit is contained in:
Matt Brown 2021-05-01 20:00:01 -04:00
parent 83a0325c0a
commit 3a87f18b5a
2 changed files with 23 additions and 5 deletions

View File

@ -160,9 +160,20 @@ class Reconciler
$orred_type = null;
foreach ($new_type_part_parts as $new_type_part_part) {
if ($new_type_part_part[0] === '>') {
/** @var array<string, array<int, array<int, string>>> */
$data = \json_decode(substr($new_type_part_part, 1), true);
if ($new_type_part_part[0] === '>'
|| ($new_type_part_part[0] === '!'
&& $new_type_part_part[1] === '>')
) {
if ($new_type_part_part[0] === '!') {
$nested_negated = !$negated;
/** @var array<string, array<int, array<int, string>>> */
$data = \json_decode(substr($new_type_part_part, 2), true);
} else {
$nested_negated = $negated;
/** @var array<string, array<int, array<int, string>>> */
$data = \json_decode(substr($new_type_part_part, 1), true);
}
$existing_types = self::reconcileKeyedTypes(
$data,
@ -174,10 +185,10 @@ class Reconciler
$template_type_map,
$inside_loop,
$code_location,
$negated
$nested_negated
);
$new_type_part_part = '!falsy';
$new_type_part_part = ($nested_negated ? '' : '!') . 'falsy';
}
$result_type_candidate = AssertionReconciler::reconcile(

View File

@ -449,6 +449,13 @@ class AssignmentInConditionalTest extends \Psalm\Tests\TestCase
[],
'8.0'
],
'assignmentForComparison' => [
'<?php
function foo(int $b): void {
if ($a = $b > 1) {}
if ($a) {}
}'
],
];
}