diff --git a/src/Type/MixedType.php b/src/Type/MixedType.php index 86c5ee6626..865611056f 100644 --- a/src/Type/MixedType.php +++ b/src/Type/MixedType.php @@ -478,8 +478,10 @@ function () use ($level): string { public function toBoolean(): BooleanType { - if ($this->subtractedType !== null && StaticTypeFactory::falsey()->equals($this->subtractedType)) { - return new ConstantBooleanType(true); + if ($this->subtractedType !== null) { + if ($this->subtractedType->isSuperTypeOf(StaticTypeFactory::falsey())->yes()) { + return new ConstantBooleanType(true); + } } return new BooleanType(); diff --git a/tests/PHPStan/Analyser/nsrt/mixed-subtract.php b/tests/PHPStan/Analyser/nsrt/mixed-subtract.php index 31c201d165..59fa2afa13 100644 --- a/tests/PHPStan/Analyser/nsrt/mixed-subtract.php +++ b/tests/PHPStan/Analyser/nsrt/mixed-subtract.php @@ -53,4 +53,9 @@ function subtract(mixed $m, $moreThenFalsy) { assertType('mixed', $m); assertType('bool', (bool) $m); // could be true } + + if ($m != 0 && !is_array($m) && $m != null && !is_object($m)) { // subtract more types then falsy + assertType("mixed~(0|0.0|''|'0'|array|object|false|null)", $m); + assertType('true', (bool) $m); + } }