Skip to content

Commit

Permalink
Fix ObjectType::equals() when compared to EnumCaseObjectType
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jan 18, 2022
1 parent 121e021 commit ab0245c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Type/ObjectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,10 @@ public function equals(Type $type): bool
return false;
}

if ($type instanceof EnumCaseObjectType) {
return false;
}

if ($this->className !== $type->className) {
return false;
}
Expand Down
9 changes: 9 additions & 0 deletions tests/PHPStan/Rules/Comparison/MatchExpressionRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,13 @@ public function testEnums(): void
]);
}

public function testBug6394(): void
{
if (PHP_VERSION_ID < 80100) {
$this->markTestSkipped('Test requires PHP 8.1.');
}

$this->analyse([__DIR__ . '/data/bug-6394.php'], []);
}

}
26 changes: 26 additions & 0 deletions tests/PHPStan/Rules/Comparison/data/bug-6394.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Bug6394;

enum EntryType: string
{
case CREDIT = 'credit';
case DEBIT = 'debit';
}

class Foo
{

public function getType(): EntryType
{
return $this->type;
}

public function getAmount(): int
{
return match($this->getType()) {
EntryType::DEBIT => 1,
EntryType::CREDIT => 2,
};
}
}

0 comments on commit ab0245c

Please sign in to comment.