1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Improce enum case reconciliation

Fixes vimeo/psalm#9456
This commit is contained in:
Bruce Weirdan 2023-03-05 16:34:51 -04:00
parent 3af9ccde91
commit f801561ea7
No known key found for this signature in database
GPG Key ID: CFC3AAB181751B0D
2 changed files with 24 additions and 0 deletions

View File

@ -945,6 +945,15 @@ class AssertionReconciler extends Reconciler
$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;

View File

@ -527,6 +527,21 @@ class EnumTest extends TestCase
'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',
],
];
}