Commit 38f6006
committed
Fix phpstan/phpstan#14473: false positive logicalOr.leftAlwaysTrue on repeated builtin function call
When a builtin function with possible side effects (like mysqli_connect())
was assigned with the `or die()` pattern, the conditional expression
mechanism stored a narrowed type for the function call expression in the
scope. On a subsequent assignment of the same function call, this stale
type was retrieved instead of the fresh return type, causing a false
positive "left side of or is always true" error.
The fix skips creating conditional expressions for FuncCall expressions
that refer to builtin functions with possible side effects, since those
function calls can return different values each time and the narrowed
type should not persist across assignments.1 parent 58b873f commit 38f6006
3 files changed
Lines changed: 59 additions & 2 deletions
File tree
- src/Analyser/ExprHandler
- tests/PHPStan/Rules/Comparison
- data
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
| |||
84 | 85 | | |
85 | 86 | | |
86 | 87 | | |
| 88 | + | |
87 | 89 | | |
88 | 90 | | |
89 | 91 | | |
| |||
861 | 863 | | |
862 | 864 | | |
863 | 865 | | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
864 | 870 | | |
865 | 871 | | |
866 | 872 | | |
867 | | - | |
868 | 873 | | |
869 | 874 | | |
870 | 875 | | |
| |||
900 | 905 | | |
901 | 906 | | |
902 | 907 | | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
903 | 912 | | |
904 | 913 | | |
905 | 914 | | |
906 | | - | |
907 | 915 | | |
908 | 916 | | |
909 | 917 | | |
| |||
924 | 932 | | |
925 | 933 | | |
926 | 934 | | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
927 | 950 | | |
928 | 951 | | |
929 | 952 | | |
| |||
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
384 | 384 | | |
385 | 385 | | |
386 | 386 | | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
387 | 394 | | |
| 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 | + | |
0 commit comments