Skip to content

Commit ab0245c

Browse files
committed
Fix ObjectType::equals() when compared to EnumCaseObjectType
1 parent 121e021 commit ab0245c

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

src/Type/ObjectType.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,10 @@ public function equals(Type $type): bool
327327
return false;
328328
}
329329

330+
if ($type instanceof EnumCaseObjectType) {
331+
return false;
332+
}
333+
330334
if ($this->className !== $type->className) {
331335
return false;
332336
}

tests/PHPStan/Rules/Comparison/MatchExpressionRuleTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,13 @@ public function testEnums(): void
158158
]);
159159
}
160160

161+
public function testBug6394(): void
162+
{
163+
if (PHP_VERSION_ID < 80100) {
164+
$this->markTestSkipped('Test requires PHP 8.1.');
165+
}
166+
167+
$this->analyse([__DIR__ . '/data/bug-6394.php'], []);
168+
}
169+
161170
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Bug6394;
4+
5+
enum EntryType: string
6+
{
7+
case CREDIT = 'credit';
8+
case DEBIT = 'debit';
9+
}
10+
11+
class Foo
12+
{
13+
14+
public function getType(): EntryType
15+
{
16+
return $this->type;
17+
}
18+
19+
public function getAmount(): int
20+
{
21+
return match($this->getType()) {
22+
EntryType::DEBIT => 1,
23+
EntryType::CREDIT => 2,
24+
};
25+
}
26+
}

0 commit comments

Comments
 (0)