1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-29 20:28:59 +01:00

Fix #5049 - assertion of !empty on bool makes true

This commit is contained in:
Matt Brown 2021-01-19 17:19:47 -05:00 committed by Daniil Gentili
parent 5e75140ca5
commit 0c52f528bd
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
3 changed files with 21 additions and 0 deletions

View File

@ -586,6 +586,12 @@ class SimpleNegatedAssertionReconciler extends Reconciler
}
}
if ($existing_var_type->hasBool()) {
$existing_var_type->removeType('bool');
$existing_var_type->addType(new Type\Atomic\TTrue);
}
self::removeFalsyNegatedLiteralTypes(
$existing_var_type,
$did_remove_type

View File

@ -1674,6 +1674,20 @@ class AssertAnnotationTest extends TestCase
}',
'error_message' => 'InvalidDocblock',
],
'assertNotEmptyOnBool' => [
'<?php
/**
* @param mixed $value
* @psalm-assert !empty $value
*/
function assertNotEmpty($value) : void {}
function foo(bool $bar) : void {
assertNotEmpty($bar);
if ($bar) {}
}',
'error_message' => 'RedundantConditionGivenDocblockType',
],
];
}
}

View File

@ -132,6 +132,7 @@ class ReconcilerTest extends \Psalm\Tests\TestCase
'iterableWithParamsToTraversableWithParams' => ['Traversable<int, string>', '!array', 'iterable<int, string>'],
'iterableAndObject' => ['Traversable<int, string>', 'object', 'iterable<int, string>'],
'iterableAndNotObject' => ['array<int, string>', '!object', 'iterable<int, string>'],
'boolNotEmptyIsTrue' => ['true', '!empty', 'bool'],
];
}