Skip to content

Commit 4321913

Browse files
jiripudilondrejmirtes
authored andcommitted
fix: star projection is always within template type bounds
1 parent 1a55bef commit 4321913

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

src/Rules/Generics/GenericObjectTypeCheck.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ public function check(
140140
continue;
141141
}
142142

143+
if ($genericTypeVariance->bivariant()) {
144+
continue;
145+
}
146+
143147
$messages[] = RuleErrorBuilder::message(sprintf(
144148
$typeIsNotSubtypeMessage,
145149
$genericTypeType->describe(VerbosityLevel::typeOnly()),

tests/PHPStan/Rules/PhpDoc/IncompatiblePhpDocTypeRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,4 +286,9 @@ public function testParamOut(): void
286286
]);
287287
}
288288

289+
public function testBug10097(): void
290+
{
291+
$this->analyse([__DIR__ . '/data/bug-10097.php'], []);
292+
}
293+
289294
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug10097;
4+
5+
interface SomeMessage {}
6+
7+
/**
8+
* @template T of object
9+
*/
10+
interface Consumer
11+
{
12+
/**
13+
* @param T $message
14+
*/
15+
public function process($message): void;
16+
17+
/**
18+
* @return class-string<T>
19+
*/
20+
public function getMessageType(): string;
21+
}
22+
23+
24+
/**
25+
* @extends Consumer<SomeMessage>
26+
*/
27+
interface SomeMessageConsumer extends Consumer
28+
{
29+
}
30+
31+
/**
32+
* @return list<Consumer<*>>
33+
*/
34+
function getConsumers(SomeMessageConsumer $consumerA): array
35+
{
36+
return [$consumerA];
37+
}

0 commit comments

Comments
 (0)