File tree Expand file tree Collapse file tree
tests/PHPStan/Rules/Methods Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -987,6 +987,23 @@ public function testBug14720(): void
987987 $ this ->analyse ([__DIR__ . '/data/bug-14720.php ' ], []);
988988 }
989989
990+ public function testBug2579 (): void
991+ {
992+ $ this ->checkThisOnly = false ;
993+ $ this ->checkNullables = true ;
994+ $ this ->checkUnionTypes = true ;
995+ $ this ->analyse ([__DIR__ . '/data/bug-2579.php ' ], [
996+ [
997+ 'Call to an undefined method Bug2579Methods\A1::bar(). ' ,
998+ 30 ,
999+ ],
1000+ [
1001+ 'Call to an undefined method Bug2579Methods\B1::foo(). ' ,
1002+ 31 ,
1003+ ],
1004+ ]);
1005+ }
1006+
9901007 public function testClosureBind (): void
9911008 {
9921009 $ this ->checkThisOnly = false ;
Original file line number Diff line number Diff line change 1+ <?php declare (strict_types = 1 );
2+
3+ namespace Bug2579Methods ;
4+
5+ class A {}
6+ class B {}
7+ class A1 extends A {
8+ public function foo (): void {}
9+ }
10+ class B1 extends B {
11+ public function bar (): void {}
12+ }
13+
14+ /**
15+ * @template T1 of A
16+ * @template T2 of B
17+ * @param T1|T2 $type
18+ * @return T1|T2
19+ */
20+ function f (object $ type )
21+ {
22+ return new $ type ();
23+ }
24+
25+ function test (): void
26+ {
27+ (f (new A1 ()))->foo (); // should pass
28+ (f (new B1 ()))->bar (); // should pass
29+
30+ (f (new A1 ()))->bar (); // should fail
31+ (f (new B1 ()))->foo (); // should fail
32+ }
You can’t perform that action at this time.
0 commit comments