1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Ensure that strict empty handling always happens

This commit is contained in:
Matt Brown 2020-12-01 22:50:21 -05:00
parent 5a200ca442
commit 7bd4d969a4
2 changed files with 15 additions and 1 deletions

View File

@ -555,7 +555,7 @@ class SimpleNegatedAssertionReconciler extends Reconciler
|| $existing_var_type->possibly_undefined_from_try || $existing_var_type->possibly_undefined_from_try
|| $existing_var_type->hasType('iterable'); || $existing_var_type->hasType('iterable');
if ($is_strict_equality && $assertion === 'empty') { if ($assertion === 'empty') {
$existing_var_type->removeType('null'); $existing_var_type->removeType('null');
$existing_var_type->removeType('false'); $existing_var_type->removeType('false');

View File

@ -375,6 +375,20 @@ class EmptyTest extends \Psalm\Tests\TestCase
if (empty($d[0])) {}' if (empty($d[0])) {}'
], ],
'reconcileNonEmptyArrayKey' => [
'<?php
/**
* @param array{a?: string, b: string} $arr
*/
function createFromString(array $arr): void
{
if (empty($arr["a"])) {
return;
}
echo $arr["a"];
}'
],
]; ];
} }