Commit a39ffdc
Fix array dim fetch type not reflecting narrowed variable key
- When an expression type holder exists for $arr[$var] (e.g. from array_key_exists),
and $var is later narrowed (e.g. in a switch/case), recompute the offset value type
using the narrowed variable type and use it if it's more specific
- New regression test in tests/PHPStan/Analyser/nsrt/bug-11705.php
- The root cause was that array_key_exists creates an expression type holder for
$arr[$tag] based on the broad value type, which overrides fresh computation even
after $tag is narrowed to a specific constant in a switch case
Closes phpstan/phpstan#117051 parent ba4fe14 commit a39ffdc
File tree
2 files changed
+49
-1
lines changed- src/Analyser
- tests/PHPStan/Analyser/nsrt
2 files changed
+49
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
979 | 979 | | |
980 | 980 | | |
981 | 981 | | |
982 | | - | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
983 | 996 | | |
984 | 997 | | |
985 | 998 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
0 commit comments