Commit a14cdce
Use @var PHPDoc type for dynamicConstantNames instead of falling back to mixed
When a class constant has a @var PHPDoc type annotation and is listed in
dynamicConstantNames, use the PHPDoc type instead of generalizing the
literal value. This fixes the primary use case from phpstan/phpstan#9218
where `@var string|null` on a null-valued constant was ignored.
The fix adds a $phpDocType parameter to resolveClassConstantType() and
passes it from both call sites in InitializerExprTypeResolver. The
priority is: native type > PHPDoc type > generalized value > mixed.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>1 parent 98e77b9 commit a14cdce
4 files changed
Lines changed: 20 additions & 1 deletion
File tree
- src
- Analyser
- Reflection
- tests/PHPStan/Analyser
- data
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
435 | 435 | | |
436 | 436 | | |
437 | 437 | | |
438 | | - | |
| 438 | + | |
439 | 439 | | |
440 | 440 | | |
441 | 441 | | |
| |||
458 | 458 | | |
459 | 459 | | |
460 | 460 | | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
461 | 465 | | |
462 | 466 | | |
463 | 467 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2544 | 2544 | | |
2545 | 2545 | | |
2546 | 2546 | | |
| 2547 | + | |
2547 | 2548 | | |
2548 | 2549 | | |
2549 | 2550 | | |
2550 | 2551 | | |
2551 | 2552 | | |
| 2553 | + | |
2552 | 2554 | | |
2553 | 2555 | | |
2554 | 2556 | | |
| |||
2577 | 2579 | | |
2578 | 2580 | | |
2579 | 2581 | | |
| 2582 | + | |
2580 | 2583 | | |
2581 | 2584 | | |
2582 | 2585 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
21 | 27 | | |
22 | 28 | | |
23 | 29 | | |
| |||
45 | 51 | | |
46 | 52 | | |
47 | 53 | | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
48 | 58 | | |
49 | 59 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
| 12 | + | |
11 | 13 | | |
12 | 14 | | |
13 | 15 | | |
| |||
0 commit comments