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

Merge pull request #9457 from weirdan/improve-enum-case-reconciliation

This commit is contained in:
Bruce Weirdan 2023-03-05 16:58:27 -04:00 committed by GitHub
commit dc4516b408
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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',
],
];
}