Skip to content

Commit

Permalink
Improce enum case reconciliation
Browse files Browse the repository at this point in the history
  • Loading branch information
weirdan committed Mar 5, 2023
1 parent 3af9ccd commit f801561
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Psalm/Internal/Type/AssertionReconciler.php
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,15 @@ private static function handleLiteralEquality(
$redundant = false;
$existing_var_type->removeType($atomic_key);
$existing_var_type->addType(new TEnumCase($fq_enum_name, $case_name));
} elseif (AtomicTypeComparator::canBeIdentical(
$statements_analyzer->getCodebase(),
$atomic_type,
$assertion_type,
)) {
$can_be_equal = true;
$redundant = $atomic_key === $assertion_type->getKey();
$existing_var_type->removeType($atomic_key);
$existing_var_type->addType(new TEnumCase($fq_enum_name, $case_name));
} elseif ($atomic_key !== $assertion_type->getKey()) {
$existing_var_type->removeType($atomic_key);
$redundant = false;
Expand Down
15 changes: 15 additions & 0 deletions tests/EnumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,21 @@ interface I extends BackedEnum {}
'ignored_issues' => [],
'php_version' => '8.1',
],
'reconcileCaseWithInterface' => [
'code' => <<<'PHP'
<?php
interface I {}
enum E implements I { case A; }
function f(I $i): void {
if ($i === E::A) {
} else {
}
}
PHP,
'assertions' => [],
'ignored_issues' => [],
'php_version' => '8.1',
],
];
}

Expand Down

0 comments on commit f801561

Please sign in to comment.