File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed
tests/PHPStan/Rules/Comparison Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff 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 ' ], []);
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments