Skip to content

Commit ef28940

Browse files
phpstan-botstaabm
andauthored
Add regression test for invariant template type narrowed by control flow in a method getter (#5922)
Co-authored-by: staabm <120441+staabm@users.noreply.github.com>
1 parent 302796a commit ef28940

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

tests/PHPStan/Rules/Methods/ReturnTypeRuleTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,4 +1353,10 @@ public function testBug12110(): void
13531353
$this->analyse([__DIR__ . '/data/bug-12110.php'], []);
13541354
}
13551355

1356+
#[RequiresPhp('>= 8.2.0')]
1357+
public function testBug11776(): void
1358+
{
1359+
$this->analyse([__DIR__ . '/data/bug-11776.php'], []);
1360+
}
1361+
13561362
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php // lint >= 8.2
2+
3+
declare(strict_types=1);
4+
5+
namespace Bug11776;
6+
7+
/**
8+
* @template TOperation of int|string
9+
*/
10+
interface EnumAsFilterInterface {}
11+
12+
/**
13+
* @template TOperation of scalar
14+
*/
15+
final readonly class ScalarableChoice
16+
{
17+
/**
18+
* @param class-string<EnumAsFilterInterface<(int|string)&TOperation>> $choiceClassName
19+
*/
20+
public function __construct(private string $choiceClassName) {}
21+
22+
/**
23+
* @return class-string<EnumAsFilterInterface<(int|string)&TOperation>>
24+
*/
25+
public function getChoiceClassName(): string
26+
{
27+
return $this->choiceClassName;
28+
}
29+
}

0 commit comments

Comments
 (0)