From 42b015de21a0e11788f844788bb5a60f5f5ab520 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Thu, 15 Dec 2022 17:37:06 +0100 Subject: [PATCH] Revert "Explicit NeverType: accept nothing" This reverts commit 25c8312dd25a301d2478ffbe109cb095d5031c85. --- src/Type/NeverType.php | 4 -- .../Rules/Functions/CallCallablesRuleTest.php | 10 --- .../PHPStan/Rules/Functions/data/bug-6485.php | 31 ---------- .../Rules/Methods/CallMethodsRuleTest.php | 4 -- tests/PHPStan/Type/NeverTypeTest.php | 61 ------------------- 5 files changed, 110 deletions(-) delete mode 100644 tests/PHPStan/Rules/Functions/data/bug-6485.php delete mode 100644 tests/PHPStan/Type/NeverTypeTest.php diff --git a/src/Type/NeverType.php b/src/Type/NeverType.php index c4aecc2c4f..cf8a719e39 100644 --- a/src/Type/NeverType.php +++ b/src/Type/NeverType.php @@ -63,10 +63,6 @@ public function getConstantStrings(): array public function accepts(Type $type, bool $strictTypes): TrinaryLogic { - if ($this->isExplicit()) { - return $this->isSuperTypeOf($type); - } - return TrinaryLogic::createYes(); } diff --git a/tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php b/tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php index bf9659e5fe..8dbd5fba42 100644 --- a/tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php +++ b/tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php @@ -262,14 +262,4 @@ public function testStaticCallInFunctions(): void $this->analyse([__DIR__ . '/data/static-call-in-functions.php'], []); } - public function testBug6485(): void - { - $this->analyse([__DIR__ . '/data/bug-6485.php'], [ - [ - 'Parameter #1 $ of closure expects *NEVER*, TBlockType of Bug6485\\Block given.', - 28, - ], - ]); - } - } diff --git a/tests/PHPStan/Rules/Functions/data/bug-6485.php b/tests/PHPStan/Rules/Functions/data/bug-6485.php deleted file mode 100644 index 92d6beff69..0000000000 --- a/tests/PHPStan/Rules/Functions/data/bug-6485.php +++ /dev/null @@ -1,31 +0,0 @@ - - */ - private array $serializers = []; - - /** - * @template TBlockType of Block - * @param TBlockType $block - */ - public function serialize(Block $block): mixed - { - $class = get_class($block); - $serializer = $this->serializers[$class] ?? null; - - if ($serializer === null){ - throw new \InvalidArgumentException(); - } - - return $serializer($block); - } - -} diff --git a/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php b/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php index 616ee5df70..826e1df3c6 100644 --- a/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php +++ b/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php @@ -2584,10 +2584,6 @@ public function testUnresolvableParameter(): void 'Parameter #2 $v of method UnresolvableParameter\HelloWorld::foo() contains unresolvable type.', 19, ], - [ - 'Parameter #2 $v of method UnresolvableParameter\HelloWorld::foo() expects *NEVER*, 0 given.', - 20, - ], ]); } diff --git a/tests/PHPStan/Type/NeverTypeTest.php b/tests/PHPStan/Type/NeverTypeTest.php deleted file mode 100644 index d2db2ab9b6..0000000000 --- a/tests/PHPStan/Type/NeverTypeTest.php +++ /dev/null @@ -1,61 +0,0 @@ - [ - new NeverType(), - new NeverType(), - TrinaryLogic::createYes(), - ], - 1 => [ - new NeverType(true), - new NeverType(), - TrinaryLogic::createYes(), - ], - 2 => [ - new NeverType(), - new NeverType(true), - TrinaryLogic::createYes(), - ], - 3 => [ - new NeverType(true), - new NeverType(true), - TrinaryLogic::createYes(), - ], - 4 => [ - new NeverType(), - new MixedType(), - TrinaryLogic::createYes(), - ], - 5 => [ - new NeverType(true), - new MixedType(), - TrinaryLogic::createNo(), - ], - ]; - } - - /** - * @dataProvider dataAccepts - */ - public function testAccepts(NeverType $type, Type $acceptedType, TrinaryLogic $expectedResult): void - { - $actualResult = $type->accepts($acceptedType, true); - $this->assertSame( - $expectedResult->describe(), - $actualResult->describe(), - sprintf('%s -> accepts(%s)', $type->describe(VerbosityLevel::precise()), $acceptedType->describe(VerbosityLevel::precise())), - ); - } - -}