Skip to content

Commit f7d80d6

Browse files
committed
EnumCaseObjectType cannot be compared in a numeric sense
1 parent 3b0a70e commit f7d80d6

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

src/Type/Enum/EnumCaseObjectType.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,16 @@ public function generalize(GeneralizePrecision $precision): Type
132132
return new parent($this->getClassName(), null, $this->getClassReflection());
133133
}
134134

135+
public function isSmallerThan(Type $otherType): TrinaryLogic
136+
{
137+
return TrinaryLogic::createNo();
138+
}
139+
140+
public function isSmallerThanOrEqual(Type $otherType): TrinaryLogic
141+
{
142+
return TrinaryLogic::createNo();
143+
}
144+
135145
/**
136146
* @param mixed[] $properties
137147
*/

tests/PHPStan/Rules/Comparison/NumberComparisonOperatorsConstantConditionRuleTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,29 @@ public function testBug5295(): void
101101
$this->analyse([__DIR__ . '/data/bug-5295.php'], []);
102102
}
103103

104+
public function testBug7052(): void
105+
{
106+
if (PHP_VERSION_ID < 80100 && !self::$useStaticReflectionProvider) {
107+
$this->markTestSkipped('Test requires PHP 8.1.');
108+
}
109+
$this->analyse([__DIR__ . '/data/bug-7052.php'], [
110+
[
111+
'Comparison operation ">" between Bug7052\Foo::A and Bug7052\Foo::B is always false.',
112+
16,
113+
],
114+
[
115+
'Comparison operation "<" between Bug7052\Foo::A and Bug7052\Foo::B is always false.',
116+
17,
117+
],
118+
[
119+
'Comparison operation ">=" between Bug7052\Foo::A and Bug7052\Foo::B is always false.',
120+
18,
121+
],
122+
[
123+
'Comparison operation "<=" between Bug7052\Foo::A and Bug7052\Foo::B is always false.',
124+
19,
125+
],
126+
]);
127+
}
128+
104129
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Bug7052;
4+
5+
enum Foo: int
6+
{
7+
case A = 1;
8+
case B = 2;
9+
}
10+
11+
class Bar
12+
{
13+
14+
public function doFoo()
15+
{
16+
Foo::A > Foo::B;
17+
Foo::A < Foo::B;
18+
Foo::A >= Foo::B;
19+
Foo::A <= Foo::B;
20+
}
21+
22+
}

0 commit comments

Comments
 (0)