Skip to content

Commit 21ebba9

Browse files
Add non regression test
1 parent 8ae740c commit 21ebba9

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,11 @@ public function testBug10884(): void
10011001
$this->analyse([__DIR__ . '/data/bug-10884.php'], []);
10021002
}
10031003

1004+
public function testBug3761(): void
1005+
{
1006+
$this->analyse([__DIR__ . '/data/bug-3761.php'], []);
1007+
}
1008+
10041009
public function testBug13208(): void
10051010
{
10061011
$this->analyse([__DIR__ . '/data/bug-13208.php'], []);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug3761;
4+
5+
class NamedTag{
6+
public function getValue() : int{
7+
return 1;
8+
}
9+
}
10+
11+
class SubclassOfNamedTag extends NamedTag{}
12+
13+
class OtherSubclassOfNamedTag extends NamedTag{}
14+
15+
class HelloWorld
16+
{
17+
public function getTag() : ?NamedTag{
18+
return new SubclassOfNamedTag();
19+
}
20+
21+
/**
22+
* @phpstan-param class-string<NamedTag> $class
23+
*/
24+
public function getTagValue(string $class = NamedTag::class) : int{
25+
$tag = $this->getTag();
26+
if($tag instanceof $class){
27+
return $tag->getValue();
28+
}
29+
30+
throw new \RuntimeException(($tag === null ? "Missing" : get_class($tag)));
31+
}
32+
}
33+
34+
(new HelloWorld())->getTagValue(OtherSubclassOfNamedTag::class); //runtime exception: SubclassOfNamedTag

0 commit comments

Comments
 (0)