diff --git a/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php b/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php index f7deb21cb77..4e68a57d38a 100644 --- a/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php @@ -236,12 +236,12 @@ public static function verifyReturnType( } $number_of_types = count($inferred_return_type_parts); - // we filter TNever and TEmpty that have no bearing on the return type + // we filter TNever that have no bearing on the return type if ($number_of_types > 1) { $inferred_return_type_parts = array_filter( $inferred_return_type_parts, static function (Union $union_type): bool { - return !($union_type->isNever() || $union_type->isEmpty()); + return !$union_type->isNever(); } ); } diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/ForeachAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/ForeachAnalyzer.php index a1d447d8076..cf99952484b 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/ForeachAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/ForeachAnalyzer.php @@ -40,7 +40,6 @@ use Psalm\Type\Atomic\Scalar; use Psalm\Type\Atomic\TArray; use Psalm\Type\Atomic\TDependentListKey; -use Psalm\Type\Atomic\TEmpty; use Psalm\Type\Atomic\TFalse; use Psalm\Type\Atomic\TGenericObject; use Psalm\Type\Atomic\TIntRange; @@ -49,9 +48,9 @@ use Psalm\Type\Atomic\TList; use Psalm\Type\Atomic\TMixed; use Psalm\Type\Atomic\TNamedObject; +use Psalm\Type\Atomic\TNever; use Psalm\Type\Atomic\TNonEmptyArray; use Psalm\Type\Atomic\TNonEmptyList; -use Psalm\Type\Atomic\TNever; use Psalm\Type\Atomic\TNull; use Psalm\Type\Atomic\TObject; use Psalm\Type\Atomic\TObjectWithProperties; diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/ArithmeticOpAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/ArithmeticOpAnalyzer.php index 47a1854c971..d2f25db887c 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/ArithmeticOpAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/ArithmeticOpAnalyzer.php @@ -44,7 +44,6 @@ use Psalm\Type\Atomic\TTemplateParam; use Psalm\Type\Union; -use Psalm\Type\Union; use function array_diff_key; use function array_values; use function count; diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/AtomicMethodCallAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/AtomicMethodCallAnalyzer.php index 7b0108399b2..0d43bc44af5 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/AtomicMethodCallAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/AtomicMethodCallAnalyzer.php @@ -26,12 +26,12 @@ use Psalm\Storage\ClassLikeStorage; use Psalm\Type; use Psalm\Type\Atomic; -use Psalm\Type\Atomic\TEmpty; use Psalm\Type\Atomic\TEmptyMixed; use Psalm\Type\Atomic\TFalse; use Psalm\Type\Atomic\TGenericObject; use Psalm\Type\Atomic\TMixed; use Psalm\Type\Atomic\TNamedObject; +use Psalm\Type\Atomic\TNever; use Psalm\Type\Atomic\TNonEmptyMixed; use Psalm\Type\Atomic\TNull; use Psalm\Type\Atomic\TObject; diff --git a/src/Psalm/Internal/Codebase/ConstantTypeResolver.php b/src/Psalm/Internal/Codebase/ConstantTypeResolver.php index 39fee635072..ca73df95f72 100644 --- a/src/Psalm/Internal/Codebase/ConstantTypeResolver.php +++ b/src/Psalm/Internal/Codebase/ConstantTypeResolver.php @@ -24,7 +24,6 @@ use Psalm\Type; use Psalm\Type\Atomic; use Psalm\Type\Atomic\TArray; -use Psalm\Type\Atomic\TEmpty; use Psalm\Type\Atomic\TFalse; use Psalm\Type\Atomic\TKeyedArray; use Psalm\Type\Atomic\TLiteralClassString; @@ -32,6 +31,7 @@ use Psalm\Type\Atomic\TLiteralInt; use Psalm\Type\Atomic\TLiteralString; use Psalm\Type\Atomic\TMixed; +use Psalm\Type\Atomic\TNever; use Psalm\Type\Atomic\TNull; use Psalm\Type\Atomic\TString; use Psalm\Type\Atomic\TTrue; diff --git a/src/Psalm/Internal/Stubs/Generator/StubsGenerator.php b/src/Psalm/Internal/Stubs/Generator/StubsGenerator.php index d17b843d1c3..0f3aaa3162a 100644 --- a/src/Psalm/Internal/Stubs/Generator/StubsGenerator.php +++ b/src/Psalm/Internal/Stubs/Generator/StubsGenerator.php @@ -23,7 +23,6 @@ use Psalm\Type\Atomic\TDependentGetDebugType; use Psalm\Type\Atomic\TDependentGetType; use Psalm\Type\Atomic\TDependentListKey; -use Psalm\Type\Atomic\TEmpty; use Psalm\Type\Atomic\TEmptyMixed; use Psalm\Type\Atomic\TEmptyNumeric; use Psalm\Type\Atomic\TEmptyScalar; diff --git a/src/Psalm/Internal/Type/Comparator/ArrayTypeComparator.php b/src/Psalm/Internal/Type/Comparator/ArrayTypeComparator.php index fd083d74224..e2857d52bab 100644 --- a/src/Psalm/Internal/Type/Comparator/ArrayTypeComparator.php +++ b/src/Psalm/Internal/Type/Comparator/ArrayTypeComparator.php @@ -7,7 +7,6 @@ use Psalm\Type\Atomic; use Psalm\Type\Atomic\TArray; use Psalm\Type\Atomic\TClassStringMap; -use Psalm\Type\Atomic\TEmpty; use Psalm\Type\Atomic\TKeyedArray; use Psalm\Type\Atomic\TList; use Psalm\Type\Atomic\TLiteralInt; diff --git a/src/Psalm/Internal/Type/Comparator/AtomicTypeComparator.php b/src/Psalm/Internal/Type/Comparator/AtomicTypeComparator.php index a33cc018535..22b655b04d2 100644 --- a/src/Psalm/Internal/Type/Comparator/AtomicTypeComparator.php +++ b/src/Psalm/Internal/Type/Comparator/AtomicTypeComparator.php @@ -15,7 +15,6 @@ use Psalm\Type\Atomic\TClassStringMap; use Psalm\Type\Atomic\TClosure; use Psalm\Type\Atomic\TConditional; -use Psalm\Type\Atomic\TEmpty; use Psalm\Type\Atomic\TEmptyMixed; use Psalm\Type\Atomic\TEnumCase; use Psalm\Type\Atomic\TGenericObject; diff --git a/src/Psalm/Internal/Type/SimpleAssertionReconciler.php b/src/Psalm/Internal/Type/SimpleAssertionReconciler.php index 5e85b7484c2..a1a7b8c128f 100644 --- a/src/Psalm/Internal/Type/SimpleAssertionReconciler.php +++ b/src/Psalm/Internal/Type/SimpleAssertionReconciler.php @@ -2279,7 +2279,7 @@ private static function reconcileFalsyOrEmpty( $failed_reconciliation = 2; - return Type::getEmpty(); + return Type::getNever(); } if (!$did_remove_type) { @@ -2311,8 +2311,8 @@ private static function reconcileFalsyOrEmpty( $existing_var_type->removeType('array'); $existing_var_type->addType(new TArray( [ - new Union([new TEmpty()]), - new Union([new TEmpty()]), + new Union([new TNever()]), + new Union([new TNever()]), ] )); } diff --git a/src/Psalm/Internal/Type/SimpleNegatedAssertionReconciler.php b/src/Psalm/Internal/Type/SimpleNegatedAssertionReconciler.php index c02160a8173..d5754977aae 100644 --- a/src/Psalm/Internal/Type/SimpleNegatedAssertionReconciler.php +++ b/src/Psalm/Internal/Type/SimpleNegatedAssertionReconciler.php @@ -25,6 +25,7 @@ use Psalm\Type\Atomic\TLowercaseString; use Psalm\Type\Atomic\TMixed; use Psalm\Type\Atomic\TNamedObject; +use Psalm\Type\Atomic\TNever; use Psalm\Type\Atomic\TNonEmptyArray; use Psalm\Type\Atomic\TNonEmptyList; use Psalm\Type\Atomic\TNonEmptyLowercaseString; @@ -34,7 +35,6 @@ use Psalm\Type\Atomic\TNonEmptyString; use Psalm\Type\Atomic\TNonFalsyString; use Psalm\Type\Atomic\TNonspecificLiteralString; -use Psalm\Type\Atomic\TNever; use Psalm\Type\Atomic\TNumeric; use Psalm\Type\Atomic\TPositiveInt; use Psalm\Type\Atomic\TScalar; @@ -618,7 +618,7 @@ private static function reconcileFalsyOrEmpty( $failed_reconciliation = 2; - return Type::getEmpty(); + return Type::getNever(); } if (!$did_remove_type) { diff --git a/src/Psalm/Internal/Type/TypeExpander.php b/src/Psalm/Internal/Type/TypeExpander.php index 8a7efecaeb2..a866410d3e8 100644 --- a/src/Psalm/Internal/Type/TypeExpander.php +++ b/src/Psalm/Internal/Type/TypeExpander.php @@ -13,7 +13,6 @@ use Psalm\Type\Atomic\TClassString; use Psalm\Type\Atomic\TClosure; use Psalm\Type\Atomic\TConditional; -use Psalm\Type\Atomic\TEmpty; use Psalm\Type\Atomic\TGenericObject; use Psalm\Type\Atomic\TInt; use Psalm\Type\Atomic\TIntMask; @@ -825,13 +824,12 @@ private static function expandConditional( ); $number_of_types = count($all_conditional_return_types); - // we filter TNever and TEmpty that have no bearing on the return type + // we filter TNever that have no bearing on the return type if ($number_of_types > 1) { $all_conditional_return_types = array_filter( $all_conditional_return_types, static function (Atomic $atomic_type): bool { - return !($atomic_type instanceof TEmpty - || $atomic_type instanceof TNever); + return !$atomic_type instanceof TNever; } ); } diff --git a/src/Psalm/Type.php b/src/Psalm/Type.php index 4bc031e88cd..30064de8439 100644 --- a/src/Psalm/Type.php +++ b/src/Psalm/Type.php @@ -304,16 +304,6 @@ public static function getScalar(): Union return new Union([$type]); } - /** - * @deprecated will be removed in Psalm 5. See getNever to retrieve a TNever that replaces TEmpty - */ - public static function getEmpty(): Union - { - $type = new TNever(); - - return new Union([$type]); - } - public static function getNever(): Union { $type = new TNever(); diff --git a/src/Psalm/Type/Atomic/TAssertionEmpty.php b/src/Psalm/Type/Atomic/TAssertionEmpty.php index 1f73af78eed..1b5863608b7 100644 --- a/src/Psalm/Type/Atomic/TAssertionEmpty.php +++ b/src/Psalm/Type/Atomic/TAssertionEmpty.php @@ -1,10 +1,12 @@ `. - * @deprecated Will be replaced by TNever when in type context and TAssertionEmpty for assertion context in Psalm 5 - */ -class TEmpty extends Scalar -{ - public function __toString(): string - { - return 'empty'; - } - - public function getKey(bool $include_extra = true): string - { - return 'empty'; - } - - /** - * @param array $aliased_classes - */ - public function toPhpString( - ?string $namespace, - array $aliased_classes, - ?string $this_class, - int $php_major_version, - int $php_minor_version - ): ?string { - return null; - } -} diff --git a/src/Psalm/Type/Union.php b/src/Psalm/Type/Union.php index 885ab04f001..7118641a2e4 100644 --- a/src/Psalm/Type/Union.php +++ b/src/Psalm/Type/Union.php @@ -1064,7 +1064,7 @@ public function isAlwaysFalsy(): bool continue; } - if ($atomic_type instanceof TArray && $atomic_type->getId() === 'array') { + if ($atomic_type instanceof TArray && $atomic_type->getId() === 'array') { continue; } diff --git a/tests/EnumTest.php b/tests/EnumTest.php index 7056f7a98ca..e0b6980f0c4 100644 --- a/tests/EnumTest.php +++ b/tests/EnumTest.php @@ -273,7 +273,7 @@ enum Status: int {} $_z = Status::cases(); ', 'assertions' => [ - '$_z===' => 'array', + '$_z===' => 'array', ], [], '8.1', diff --git a/tests/TypeReconciliation/ReconcilerTest.php b/tests/TypeReconciliation/ReconcilerTest.php index 96b0c0669d6..ca3d437ee48 100644 --- a/tests/TypeReconciliation/ReconcilerTest.php +++ b/tests/TypeReconciliation/ReconcilerTest.php @@ -103,7 +103,7 @@ public function providerTestReconcilation(): array 'nullWithSomeClassPipeNull' => ['null', 'null', 'SomeClass|null'], 'nullWithMixed' => ['null', 'null', 'mixed'], - 'falsyWithSomeClass' => ['empty', 'falsy', 'SomeClass'], + 'falsyWithSomeClass' => ['never', 'falsy', 'SomeClass'], 'falsyWithSomeClassPipeFalse' => ['false', 'falsy', 'SomeClass|false'], 'falsyWithSomeClassPipeBool' => ['false', 'falsy', 'SomeClass|bool'], 'falsyWithMixed' => ['empty-mixed', 'falsy', 'mixed'],