From 21ebba9422feedf333caf1c46c255b78935f069c Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Sun, 27 Jul 2025 21:07:53 +0200 Subject: [PATCH] Add non regression test --- ...rictComparisonOfDifferentTypesRuleTest.php | 5 +++ .../Rules/Comparison/data/bug-3761.php | 34 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 tests/PHPStan/Rules/Comparison/data/bug-3761.php diff --git a/tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php b/tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php index a0efad16b4..a0d1260bad 100644 --- a/tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php +++ b/tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php @@ -1001,6 +1001,11 @@ public function testBug10884(): void $this->analyse([__DIR__ . '/data/bug-10884.php'], []); } + public function testBug3761(): void + { + $this->analyse([__DIR__ . '/data/bug-3761.php'], []); + } + public function testBug13208(): void { $this->analyse([__DIR__ . '/data/bug-13208.php'], []); diff --git a/tests/PHPStan/Rules/Comparison/data/bug-3761.php b/tests/PHPStan/Rules/Comparison/data/bug-3761.php new file mode 100644 index 0000000000..01531dbc1c --- /dev/null +++ b/tests/PHPStan/Rules/Comparison/data/bug-3761.php @@ -0,0 +1,34 @@ + $class + */ + public function getTagValue(string $class = NamedTag::class) : int{ + $tag = $this->getTag(); + if($tag instanceof $class){ + return $tag->getValue(); + } + + throw new \RuntimeException(($tag === null ? "Missing" : get_class($tag))); + } +} + +(new HelloWorld())->getTagValue(OtherSubclassOfNamedTag::class); //runtime exception: SubclassOfNamedTag