From 60b40ccd9653dff7bf838790bd74a42fd7c3ae04 Mon Sep 17 00:00:00 2001 From: Yohta Kimura Date: Fri, 22 Apr 2022 09:27:54 +0900 Subject: [PATCH] class with final doesn't mean dynamic property is prohibited --- src/Type/ObjectType.php | 4 ---- .../ImpossibleCheckTypeFunctionCallRuleTest.php | 8 -------- tests/PHPStan/Type/Accessory/HasPropertyTypeTest.php | 2 +- tests/PHPStan/Type/ObjectTypeTest.php | 2 +- tests/PHPStan/Type/TypeCombinatorTest.php | 4 ++-- 5 files changed, 4 insertions(+), 16 deletions(-) diff --git a/src/Type/ObjectType.php b/src/Type/ObjectType.php index 3b11600a7e..0cd7d57b02 100644 --- a/src/Type/ObjectType.php +++ b/src/Type/ObjectType.php @@ -129,10 +129,6 @@ public function hasProperty(string $propertyName): TrinaryLogic return TrinaryLogic::createYes(); } - if ($classReflection->isFinal()) { - return TrinaryLogic::createNo(); - } - return TrinaryLogic::createMaybe(); } diff --git a/tests/PHPStan/Rules/Comparison/ImpossibleCheckTypeFunctionCallRuleTest.php b/tests/PHPStan/Rules/Comparison/ImpossibleCheckTypeFunctionCallRuleTest.php index 90fb9d5266..ea96a4e825 100644 --- a/tests/PHPStan/Rules/Comparison/ImpossibleCheckTypeFunctionCallRuleTest.php +++ b/tests/PHPStan/Rules/Comparison/ImpossibleCheckTypeFunctionCallRuleTest.php @@ -100,10 +100,6 @@ public function testImpossibleCheckTypeFunctionCall(): void 'Call to function property_exists() with $this(CheckTypeFunctionCall\FinalClassWithPropertyExists) and \'fooProperty\' will always evaluate to true.', 209, ], - [ - 'Call to function property_exists() with $this(CheckTypeFunctionCall\FinalClassWithPropertyExists) and \'barProperty\' will always evaluate to false.', - 212, - ], [ 'Call to function in_array() with arguments int, array{\'foo\', \'bar\'} and true will always evaluate to false.', 235, @@ -273,10 +269,6 @@ public function testImpossibleCheckTypeFunctionCallWithoutAlwaysTrue(): void 'Call to function method_exists() with $this(CheckTypeFunctionCall\FinalClassWithMethodExists) and \'doBar\' will always evaluate to false.', 194, ], - [ - 'Call to function property_exists() with $this(CheckTypeFunctionCall\FinalClassWithPropertyExists) and \'barProperty\' will always evaluate to false.', - 212, - ], [ 'Call to function in_array() with arguments int, array{\'foo\', \'bar\'} and true will always evaluate to false.', 235, diff --git a/tests/PHPStan/Type/Accessory/HasPropertyTypeTest.php b/tests/PHPStan/Type/Accessory/HasPropertyTypeTest.php index 79743043b0..59dc64ea4c 100644 --- a/tests/PHPStan/Type/Accessory/HasPropertyTypeTest.php +++ b/tests/PHPStan/Type/Accessory/HasPropertyTypeTest.php @@ -47,7 +47,7 @@ public function dataIsSuperTypeOf(): array [ new HasPropertyType('foo'), new ObjectType(Closure::class), - TrinaryLogic::createNo(), + TrinaryLogic::createMaybe(), ], [ new HasPropertyType('foo'), diff --git a/tests/PHPStan/Type/ObjectTypeTest.php b/tests/PHPStan/Type/ObjectTypeTest.php index 81298886b5..b435768d57 100644 --- a/tests/PHPStan/Type/ObjectTypeTest.php +++ b/tests/PHPStan/Type/ObjectTypeTest.php @@ -260,7 +260,7 @@ public function dataIsSuperTypeOf(): array 32 => [ new ObjectType(Closure::class), new HasPropertyType('d'), - TrinaryLogic::createNo(), + TrinaryLogic::createMaybe(), ], 33 => [ new ObjectType(DateInterval::class), diff --git a/tests/PHPStan/Type/TypeCombinatorTest.php b/tests/PHPStan/Type/TypeCombinatorTest.php index 8e664991f1..537ded9cf5 100644 --- a/tests/PHPStan/Type/TypeCombinatorTest.php +++ b/tests/PHPStan/Type/TypeCombinatorTest.php @@ -2512,8 +2512,8 @@ public function dataIntersect(): iterable new ObjectType(FinalClassWithPropertyExists::class), new HasPropertyType('barProperty'), ], - NeverType::class, - '*NEVER*', + IntersectionType::class, + 'CheckTypeFunctionCall\FinalClassWithPropertyExists&hasProperty(barProperty)', ], [ [