@@ -3900,6 +3900,14 @@ func TestBits(t *testing.T) {
3900
3900
testAccepts (t , "byte 0x0000; int 15; int 1; setbit; byte 0x0001; ==" , 3 )
3901
3901
testAccepts (t , "int 0x0000; int 3; int 1; setbit; int 0x0008; ==" , 3 )
3902
3902
testAccepts (t , "int 0x0000; int 12; int 1; setbit; int 0x1000; ==" , 3 )
3903
+
3904
+ // These test that setbyte is not modifying a shared value.
3905
+ // Since neither bytec nor dup copies, the first test is
3906
+ // insufficient, the setbit changes the original constant (if
3907
+ // it fails to copy).
3908
+ testAccepts (t , "byte 0xfffff0; dup; int 21; int 1; setbit; byte 0xfffff4; ==; pop; byte 0xfffff0; ==" , 3 )
3909
+ testAccepts (t , "byte 0xffff; byte 0xf0; concat; dup; int 21; int 1; setbit; byte 0xfffff4; ==; pop; byte 0xfffff0; ==" , 3 )
3910
+
3903
3911
}
3904
3912
3905
3913
func TestBytes (t * testing.T ) {
@@ -3914,8 +3922,13 @@ func TestBytes(t *testing.T) {
3914
3922
testPanics (t , `byte "john"; int 4; getbyte; int 1; ==` , 3 ) // past end
3915
3923
3916
3924
testAccepts (t , `byte "john"; int 2; int 105; setbyte; byte "join"; ==` , 3 )
3917
- // dup makes copies, modifying one does not change the other
3925
+
3926
+ // These test that setbyte is not modifying a shared value.
3927
+ // Since neither bytec nor dup copies, the first test is
3928
+ // insufficient, the setbyte changes the original constant (if
3929
+ // it fails to copy).
3918
3930
testAccepts (t , `byte "john"; dup; int 2; int 105; setbyte; pop; byte "john"; ==` , 3 )
3931
+ testAccepts (t , `byte "jo"; byte "hn"; concat; dup; int 2; int 105; setbyte; pop; byte "john"; ==` , 3 )
3919
3932
}
3920
3933
3921
3934
func TestSwap (t * testing.T ) {
0 commit comments