diff --git a/src/Type/UnionType.php b/src/Type/UnionType.php index 9ae63c6cde8..7b1792ff6a0 100644 --- a/src/Type/UnionType.php +++ b/src/Type/UnionType.php @@ -137,6 +137,13 @@ public function isSuperTypeOf(Type $otherType): TrinaryLogic return $otherType->isSubTypeOf($this); } + if ($otherType instanceof IntegerRangeType) { + $remainingType = TypeCombinator::remove($otherType, $this); + if ($remainingType instanceof NeverType) { + return TrinaryLogic::createYes(); + } + } + $result = TrinaryLogic::createNo()->lazyOr($this->getTypes(), static fn (Type $innerType) => $innerType->isSuperTypeOf($otherType)); if ($result->yes()) { return $result; diff --git a/tests/PHPStan/Rules/Properties/TypesAssignedToPropertiesRuleTest.php b/tests/PHPStan/Rules/Properties/TypesAssignedToPropertiesRuleTest.php index 84dc5c01643..ce66dc066e1 100644 --- a/tests/PHPStan/Rules/Properties/TypesAssignedToPropertiesRuleTest.php +++ b/tests/PHPStan/Rules/Properties/TypesAssignedToPropertiesRuleTest.php @@ -445,4 +445,10 @@ public function testBug4680(): void $this->analyse([__DIR__ . '/data/bug-4680.php'], []); } + public function testBug3383(): void + { + $this->checkExplicitMixed = true; + $this->analyse([__DIR__ . '/data/bug-3383.php'], []); + } + } diff --git a/tests/PHPStan/Rules/Properties/data/bug-3383.php b/tests/PHPStan/Rules/Properties/data/bug-3383.php new file mode 100644 index 00000000000..68041788dbc --- /dev/null +++ b/tests/PHPStan/Rules/Properties/data/bug-3383.php @@ -0,0 +1,13 @@ +classification = random_int(0, 3); + } +}