Commit 6291adc
vm: fix array-compound regressions via OP_ARRAY_PRE_CHECK_LOCAL
Commit ab63482 introduced OP_ARRAY_COMPOUND_ASSIGN_LOCAL and
OP_ARRAY_INC_DEC_LOCAL but missed three AST corner cases:
* assign_dim_op_undef — `$a[$b] += 1` on undefined $a should warn
"Undefined variable $a" + "Deprecated null offset" + "Undefined
array key", in that order. The native opcode evaluated the offset
first and let arrayGet's "Trying to access array offset on null"
replace the proper undefined-variable warning.
* bug53432 — `$str[0] += 1` on a string should throw "Cannot use
assign-op operators with string offsets" BEFORE the offset is
evaluated. The native path was running arrayGet + arraySetLocal
through the string-offset machinery instead.
* bug70662 — when arrayGet's undefined-key warning triggers an error
handler that creates the key, the compound write must be suppressed
so the handler's value remains visible.
Adds OP_ARRAY_PRE_CHECK_LOCAL which runs BEFORE the offset is pushed.
It mirrors runArrayAccess.Run's ZtNull / ZtString compound-write-context
branches: warn + auto-vivify undefined containers, vivify explicit
nulls, and throw "Cannot use assign-op operators with string offsets"
for string containers. Warning order now matches the AST.
OP_ARRAY_COMPOUND_ASSIGN_LOCAL and OP_ARRAY_INC_DEC_LOCAL now also:
* emit "Using null as an array offset is deprecated" in the read
phase when the offset is null and the container is array/string/
object (matches compile-array.go:712-717).
* snapshot key existence pre-arrayGet and re-check the slot post-op.
If the slot was replaced by a scalar (handler trashed it) or the
key now exists when it didn't before (handler created it), the
write is skipped (compile-array.go:826-862, bug70662 semantics).
Verified bit-identical to AST on assign_dim_op_undef, bug53432,
bug70662, plus the existing compound/incdec smoke tests.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>1 parent ba82884 commit 6291adc
3 files changed
Lines changed: 174 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
665 | 665 | | |
666 | 666 | | |
667 | 667 | | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
668 | 689 | | |
669 | 690 | | |
670 | 691 | | |
| |||
818 | 839 | | |
819 | 840 | | |
820 | 841 | | |
| 842 | + | |
821 | 843 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
918 | 918 | | |
919 | 919 | | |
920 | 920 | | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
921 | 964 | | |
922 | 965 | | |
923 | 966 | | |
924 | 967 | | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
925 | 973 | | |
926 | 974 | | |
927 | 975 | | |
| |||
933 | 981 | | |
934 | 982 | | |
935 | 983 | | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
936 | 1006 | | |
937 | 1007 | | |
938 | 1008 | | |
| |||
949 | 1019 | | |
950 | 1020 | | |
951 | 1021 | | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
952 | 1049 | | |
953 | 1050 | | |
954 | 1051 | | |
| |||
962 | 1059 | | |
963 | 1060 | | |
964 | 1061 | | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
965 | 1065 | | |
966 | 1066 | | |
967 | 1067 | | |
| |||
970 | 1070 | | |
971 | 1071 | | |
972 | 1072 | | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
973 | 1088 | | |
974 | 1089 | | |
975 | 1090 | | |
| |||
985 | 1100 | | |
986 | 1101 | | |
987 | 1102 | | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
988 | 1130 | | |
989 | 1131 | | |
990 | 1132 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1142 | 1142 | | |
1143 | 1143 | | |
1144 | 1144 | | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
1145 | 1152 | | |
1146 | 1153 | | |
1147 | 1154 | | |
1148 | 1155 | | |
1149 | 1156 | | |
1150 | 1157 | | |
1151 | | - | |
1152 | 1158 | | |
1153 | 1159 | | |
1154 | 1160 | | |
| |||
1299 | 1305 | | |
1300 | 1306 | | |
1301 | 1307 | | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
1302 | 1311 | | |
1303 | 1312 | | |
1304 | 1313 | | |
1305 | | - | |
1306 | 1314 | | |
1307 | 1315 | | |
1308 | 1316 | | |
| |||
0 commit comments