From 775c3f369c4d721293f2e29a43fcc763bcc4f587 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Wed, 17 Mar 2021 18:41:56 +0100 Subject: [PATCH] Regression test Closes https://github.com/phpstan/phpstan/issues/3118 --- .../Rules/Methods/ReturnTypeRuleTest.php | 10 ++++ tests/PHPStan/Rules/Methods/data/bug-3118.php | 58 +++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 tests/PHPStan/Rules/Methods/data/bug-3118.php diff --git a/tests/PHPStan/Rules/Methods/ReturnTypeRuleTest.php b/tests/PHPStan/Rules/Methods/ReturnTypeRuleTest.php index 584effa8bc..f998a0a306 100644 --- a/tests/PHPStan/Rules/Methods/ReturnTypeRuleTest.php +++ b/tests/PHPStan/Rules/Methods/ReturnTypeRuleTest.php @@ -479,4 +479,14 @@ public function testBug3120(): void $this->analyse([__DIR__ . '/data/bug-3120.php'], []); } + public function testBug3118(): void + { + $this->analyse([__DIR__ . '/data/bug-3118.php'], [ + [ + 'Method Bug3118\CustomEnum2::all() should return Bug3118\EnumSet but returns Bug3118\CustomEnumSet.', + 56, + ], + ]); + } + } diff --git a/tests/PHPStan/Rules/Methods/data/bug-3118.php b/tests/PHPStan/Rules/Methods/data/bug-3118.php new file mode 100644 index 0000000000..b8d7a930bf --- /dev/null +++ b/tests/PHPStan/Rules/Methods/data/bug-3118.php @@ -0,0 +1,58 @@ + $type + */ + public function __construct(string $type) + { + $this->type = $type; + } +} + +abstract class Enum +{ + /** + * @return EnumSet + */ + public static function all(): EnumSet + { + return new EnumSet(static::class); + } +} + +/** + * @extends EnumSet + */ +final class CustomEnumSet extends EnumSet +{ + + public function __construct() + { + parent::__construct(CustomEnum::class); + } +} + +final class CustomEnum extends Enum +{ + public static function all(): EnumSet + { + return new CustomEnumSet(); + } +} + +class CustomEnum2 extends Enum +{ + public static function all(): EnumSet + { + return new CustomEnumSet(); + } +}