File tree Expand file tree Collapse file tree 3 files changed +44
-0
lines changed
tests/PHPStan/Rules/Methods Expand file tree Collapse file tree 3 files changed +44
-0
lines changed Original file line number Diff line number Diff line change 55use PHPStan \PhpDocParser \Ast \Type \GenericTypeNode ;
66use PHPStan \PhpDocParser \Ast \Type \IdentifierTypeNode ;
77use PHPStan \PhpDocParser \Ast \Type \TypeNode ;
8+ use PHPStan \Type \Generic \TemplateType ;
89use PHPStan \Type \Generic \TemplateTypeVariance ;
910use PHPStan \Type \Traits \LateResolvableTypeTrait ;
1011use PHPStan \Type \Traits \NonGeneralizableTypeTrait ;
@@ -50,6 +51,13 @@ public function isResolvable(): bool
5051 protected function getResult (): Type
5152 {
5253 if ($ this ->type ->isEnum ()->yes ()) {
54+ if ($ this ->type instanceof TemplateType) {
55+ $ bound = $ this ->type ->getBound ();
56+ if ($ bound ->equals (new ObjectType ('BackedEnum ' ))) {
57+ return new UnionType ([new IntegerType (), new StringType ()]);
58+ }
59+ }
60+
5361 $ valueTypes = [];
5462 foreach ($ this ->type ->getEnumCases () as $ enumCase ) {
5563 $ valueType = $ enumCase ->getBackingValueType ();
Original file line number Diff line number Diff line change @@ -3666,6 +3666,16 @@ public function testBug3396(): void
36663666 $ this ->analyse ([__DIR__ . '/data/bug-3396.php ' ], []);
36673667 }
36683668
3669+ #[RequiresPhp('>= 8.1 ' )]
3670+ public function testBug12219 (): void
3671+ {
3672+ $ this ->checkThisOnly = false ;
3673+ $ this ->checkNullables = true ;
3674+ $ this ->checkUnionTypes = true ;
3675+ $ this ->checkExplicitMixed = true ;
3676+ $ this ->analyse ([__DIR__ . '/data/bug-12219.php ' ], []);
3677+ }
3678+
36693679 public function testBug13511 (): void
36703680 {
36713681 $ this ->checkThisOnly = false ;
Original file line number Diff line number Diff line change 1+ <?php // lint >= 8.1
2+
3+ namespace Bug12219 ;
4+
5+ class Bug
6+ {
7+ /**
8+ * @template T of \BackedEnum
9+ * @param class-string<T> $class
10+ * @param value-of<T> $value
11+ */
12+ public function foo (string $ class , mixed $ value ): void
13+ {
14+ }
15+
16+ /**
17+ * @template Q of \BackedEnum
18+ * @param class-string<Q> $class
19+ * @param value-of<Q> $value
20+ */
21+ public function bar (string $ class , mixed $ value ): void
22+ {
23+ // Parameter #2 $value of static method Bug::foo() contains unresolvable type.
24+ $ this ->foo ($ class , $ value );
25+ }
26+ }
You can’t perform that action at this time.
0 commit comments