Commit 906e8bf
Fix phpstan/phpstan#6830: Variable inside loop might not be defined
- Fixed intersectConditionalExpressions() in MutatingScope to merge conditional
expression holders with same conditions but different result types
- Previously, when a variable was conditionally defined before a loop and used
inside the loop under the same condition, the conditional expression was lost
during scope merging because the result type changed across iterations
- Added fallback logic: when exact key matching fails, match holders by their
condition expressions and merge result types via TypeCombinator::union()
- Extended regression test in tests/PHPStan/Rules/Variables/data/bug-6830.php1 parent 0c740e3 commit 906e8bf
2 files changed
Lines changed: 80 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4039 | 4039 | | |
4040 | 4040 | | |
4041 | 4041 | | |
| 4042 | + | |
4042 | 4043 | | |
4043 | 4044 | | |
4044 | | - | |
| 4045 | + | |
| 4046 | + | |
| 4047 | + | |
| 4048 | + | |
| 4049 | + | |
| 4050 | + | |
| 4051 | + | |
| 4052 | + | |
| 4053 | + | |
| 4054 | + | |
| 4055 | + | |
| 4056 | + | |
| 4057 | + | |
| 4058 | + | |
| 4059 | + | |
| 4060 | + | |
| 4061 | + | |
| 4062 | + | |
| 4063 | + | |
| 4064 | + | |
| 4065 | + | |
| 4066 | + | |
| 4067 | + | |
| 4068 | + | |
| 4069 | + | |
| 4070 | + | |
| 4071 | + | |
| 4072 | + | |
| 4073 | + | |
| 4074 | + | |
| 4075 | + | |
| 4076 | + | |
| 4077 | + | |
| 4078 | + | |
| 4079 | + | |
| 4080 | + | |
| 4081 | + | |
| 4082 | + | |
| 4083 | + | |
| 4084 | + | |
| 4085 | + | |
| 4086 | + | |
| 4087 | + | |
| 4088 | + | |
| 4089 | + | |
| 4090 | + | |
4045 | 4091 | | |
4046 | 4092 | | |
4047 | 4093 | | |
4048 | | - | |
| 4094 | + | |
| 4095 | + | |
| 4096 | + | |
| 4097 | + | |
| 4098 | + | |
4049 | 4099 | | |
4050 | 4100 | | |
4051 | 4101 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
0 commit comments