diff --git a/src/Type/UnionType.php b/src/Type/UnionType.php index 08d678152a..03255de9d9 100644 --- a/src/Type/UnionType.php +++ b/src/Type/UnionType.php @@ -676,7 +676,7 @@ public function isScalar(): TrinaryLogic public function looseCompare(Type $type, PhpVersion $phpVersion): BooleanType { - return $this->unionResults( + return $this->notBenevolentUnionResults( static fn (Type $innerType): TrinaryLogic => $innerType->looseCompare($type, $phpVersion)->toTrinaryLogic() )->toBooleanType(); } diff --git a/tests/PHPStan/Rules/Comparison/ConstantLooseComparisonRuleTest.php b/tests/PHPStan/Rules/Comparison/ConstantLooseComparisonRuleTest.php index e49a6100f7..f981f92621 100644 --- a/tests/PHPStan/Rules/Comparison/ConstantLooseComparisonRuleTest.php +++ b/tests/PHPStan/Rules/Comparison/ConstantLooseComparisonRuleTest.php @@ -242,4 +242,10 @@ public function testBug8800(): void ]); } + public function testBug13098(): void + { + $this->treatPhpDocTypesAsCertain = true; + $this->analyse([__DIR__ . '/data/bug-13098.php'], []); + } + } diff --git a/tests/PHPStan/Rules/Comparison/data/bug-13098.php b/tests/PHPStan/Rules/Comparison/data/bug-13098.php new file mode 100644 index 0000000000..b549d338fe --- /dev/null +++ b/tests/PHPStan/Rules/Comparison/data/bug-13098.php @@ -0,0 +1,15 @@ +