File tree Expand file tree Collapse file tree 3 files changed +43
-0
lines changed
Expand file tree Collapse file tree 3 files changed +43
-0
lines changed Original file line number Diff line number Diff line change 6565use PHPStan \Type \FloatType ;
6666use PHPStan \Type \Generic \GenericClassStringType ;
6767use PHPStan \Type \Generic \GenericObjectType ;
68+ use PHPStan \Type \Generic \TemplateType ;
6869use PHPStan \Type \Generic \TemplateTypeVariance ;
6970use PHPStan \Type \Helper \GetTemplateTypeType ;
7071use PHPStan \Type \IntegerRangeType ;
@@ -749,6 +750,9 @@ static function (string $variance): TemplateTypeVariance {
749750 $ mainType = $ this ->resolveIdentifierTypeNode ($ typeNode ->type , $ nameScope );
750751 $ mainTypeObjectClassNames = $ mainType ->getObjectClassNames ();
751752 if (count ($ mainTypeObjectClassNames ) > 1 ) {
753+ if ($ mainType instanceof TemplateType) {
754+ return new ErrorType ();
755+ }
752756 throw new ShouldNotHappenException ();
753757 }
754758 $ mainTypeClassName = $ mainTypeObjectClassNames [0 ] ?? null ;
Original file line number Diff line number Diff line change @@ -1286,6 +1286,14 @@ public function testBug10302(): void
12861286 $ this ->assertNoErrors ($ errors );
12871287 }
12881288
1289+ public function testBug10509 (): void
1290+ {
1291+ $ errors = $ this ->runAnalyse (__DIR__ . '/data/bug-10509.php ' );
1292+ $ this ->assertCount (2 , $ errors );
1293+ $ this ->assertSame ('Method Bug10509\Foo::doFoo() has no return type specified. ' , $ errors [0 ]->getMessage ());
1294+ $ this ->assertSame ('PHPDoc tag @return contains unresolvable type. ' , $ errors [1 ]->getMessage ());
1295+ }
1296+
12891297 /**
12901298 * @param string[]|null $allAnalysedFiles
12911299 * @return Error[]
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Bug10509 ;
4+
5+ /** @template T */
6+ interface One
7+ {
8+
9+ }
10+
11+ /** @template T */
12+ interface Two
13+ {
14+
15+ }
16+
17+ /**
18+ * @template T of One&Two
19+ */
20+ class Foo
21+ {
22+
23+ /**
24+ * @return T<int>
25+ */
26+ public function doFoo ()
27+ {
28+
29+ }
30+
31+ }
You can’t perform that action at this time.
0 commit comments