diff --git a/src/Psalm/Internal/Provider/StatementsProvider.php b/src/Psalm/Internal/Provider/StatementsProvider.php index f78bd3e83b9..d6d5d4abccc 100644 --- a/src/Psalm/Internal/Provider/StatementsProvider.php +++ b/src/Psalm/Internal/Provider/StatementsProvider.php @@ -155,10 +155,6 @@ public function getStatementsForFile( $existing_statements = $this->parser_cache_provider->loadExistingStatementsFromCache($file_path); - if ($existing_statements && !$existing_statements[0] instanceof PhpParser\Node\Stmt) { - $existing_statements = null; - } - $existing_file_contents = $this->parser_cache_provider->loadExistingFileContentsFromCache($file_path); // this happens after editing temporary file diff --git a/src/Psalm/Internal/Type/NegatedAssertionReconciler.php b/src/Psalm/Internal/Type/NegatedAssertionReconciler.php index e710a8c3c7d..efdf02d80c6 100644 --- a/src/Psalm/Internal/Type/NegatedAssertionReconciler.php +++ b/src/Psalm/Internal/Type/NegatedAssertionReconciler.php @@ -16,7 +16,6 @@ use Psalm\Type\Atomic; use Psalm\Type\Atomic\TArray; use Psalm\Type\Atomic\TClassString; -use Psalm\Type\Atomic\TEmptyMixed; use Psalm\Type\Atomic\TEnumCase; use Psalm\Type\Atomic\TFalse; use Psalm\Type\Atomic\TFloat; @@ -162,6 +161,14 @@ public static function reconcile( return $existing_var_type; } + if (!$is_equality && $assertion_type instanceof TNamedObject) { + foreach ($existing_var_type->getAtomicTypes() as $key => $type) { + if ($type instanceof TEnumCase && $type->value === $assertion_type->value) { + $existing_var_type->removeType($key); + } + } + } + $codebase = $statements_analyzer->getCodebase(); if ($assertion_type instanceof TNamedObject @@ -291,7 +298,9 @@ public static function reconcile( $failed_reconciliation = Reconciler::RECONCILIATION_EMPTY; - return new Union([new TEmptyMixed]); + return $existing_var_type->from_docblock + ? Type::getMixed() + : Type::getNever(); } return $existing_var_type; diff --git a/tests/EnumTest.php b/tests/EnumTest.php index 3297151ee2d..963614bd198 100644 --- a/tests/EnumTest.php +++ b/tests/EnumTest.php @@ -405,6 +405,35 @@ function foo(): int|Code|null 'ignored_issues' => [], 'php_version' => '8.1', ], + 'EnumCaseReconciliation' => [ + 'code' => ' [ + '$code1' => 'Code|null', + '$code2' => 'null', + ], + 'ignored_issues' => [], + 'php_version' => '8.1', + ], ]; }