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

Fix #3894 - don’t alter class-string during erroneous emptiness check

This commit is contained in:
Matthew Brown 2020-07-25 22:49:19 -04:00
parent 3f06d4f706
commit 1d077cc48e
2 changed files with 12 additions and 1 deletions

View File

@ -644,7 +644,10 @@ class SimpleNegatedAssertionReconciler extends Reconciler
}
if (isset($existing_var_atomic_types['string'])) {
if (!$existing_var_atomic_types['string'] instanceof Type\Atomic\TNonEmptyString) {
if (!$existing_var_atomic_types['string'] instanceof Type\Atomic\TNonEmptyString
&& !$existing_var_atomic_types['string'] instanceof Type\Atomic\TClassString
&& !$existing_var_atomic_types['string'] instanceof Type\Atomic\GetClassT
) {
$did_remove_type = true;
$existing_var_type->removeType('string');

View File

@ -1341,6 +1341,14 @@ class RedundantConditionTest extends \Psalm\Tests\TestCase
if ($a && $a instanceof A) {}',
'error_message' => 'RedundantConditionGivenDocblockType',
],
'classStringNotEmpty' => [
'<?php
function foo(object $o) : void {
$oc = get_class($o);
if ($oc) {}
}',
'error_message' => 'RedundantCondition',
],
];
}
}