Skip to content

Commit 1ece38f

Browse files
committed
Regression test
Closes phpstan/phpstan#6856
1 parent 0bd48b4 commit 1ece38f

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

tests/PHPStan/Analyser/NodeScopeResolverTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ public function dataFileAsserts(): iterable
119119
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-3269.php');
120120
yield from $this->gatherAssertTypes(__DIR__ . '/data/assign-nested-arrays.php');
121121
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-3276.php');
122+
yield from $this->gatherAssertTypes(__DIR__ . '/../Rules/Methods/data/bug-6856.php');
122123
yield from $this->gatherAssertTypes(__DIR__ . '/data/shadowed-trait-methods.php');
123124
yield from $this->gatherAssertTypes(__DIR__ . '/data/const-in-functions.php');
124125
yield from $this->gatherAssertTypes(__DIR__ . '/data/const-in-functions-namespaced.php');

tests/PHPStan/Rules/Methods/ReturnTypeRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -934,4 +934,9 @@ public function testLists(): void
934934
]);
935935
}
936936

937+
public function testBug6856(): void
938+
{
939+
$this->analyse([__DIR__ . '/data/bug-6856.php'], []);
940+
}
941+
937942
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
namespace Bug6856;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
/**
8+
* @template T of object
9+
*/
10+
trait TraitA {
11+
/**
12+
* @return T
13+
*/
14+
public function a(): object {
15+
return new ClassB();
16+
}
17+
18+
/**
19+
* @return T
20+
*/
21+
public function test(): object {
22+
return new ClassB();
23+
}
24+
}
25+
26+
class ClassA {
27+
/**
28+
* @phpstan-use TraitA<ClassB>
29+
*/
30+
use TraitA {
31+
a as renamed;
32+
}
33+
34+
public function a(): ClassB {
35+
return $this->renamed();
36+
}
37+
38+
public function b(): ClassB {
39+
return $this->test();
40+
}
41+
}
42+
43+
class ClassB {
44+
// empty
45+
}
46+
47+
function (ClassA $a): void {
48+
assertType(ClassB::class, $a->a());
49+
assertType(ClassB::class, $a->renamed());
50+
assertType(ClassB::class, $a->test());
51+
assertType(ClassB::class, $a->b());
52+
};

0 commit comments

Comments
 (0)