summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2016-05-20 21:55:40 -0700
committerSteve Hay <steve.m.hay@googlemail.com>2017-08-08 17:48:03 +0100
commit915d6a669585d5e94c5af2e1d2f635883eff7c01 (patch)
tree14cf89ef710dcaf4b58fe15f4cb7539ee11729e5
parentcf1efead3fa596a455f799448d561f12007787e1 (diff)
downloadperl-915d6a669585d5e94c5af2e1d2f635883eff7c01.tar.gz
[perl #128204] Fix crash with @a &.= etc.
The new bitwise operators in their assignment forms were not correctly catching things like arrays on the lhs at compile time. At run time, they would either crash or croak with ‘Can’t coerce ARRAY...’. This commit puts in the correct compile-time check, simply by flagging these as scalar modifiers. (cherry picked from commit 76734a3218e712760695898e424c2369ccdd49c6)
-rw-r--r--op.c6
-rw-r--r--t/lib/croak/op48
2 files changed, 54 insertions, 0 deletions
diff --git a/op.c b/op.c
index 5debcff720..301acc6174 100644
--- a/op.c
+++ b/op.c
@@ -3223,6 +3223,12 @@ S_scalar_mod_type(const OP *o, I32 type)
case OP_BIT_AND:
case OP_BIT_XOR:
case OP_BIT_OR:
+ case OP_NBIT_AND:
+ case OP_NBIT_XOR:
+ case OP_NBIT_OR:
+ case OP_SBIT_AND:
+ case OP_SBIT_XOR:
+ case OP_SBIT_OR:
case OP_CONCAT:
case OP_SUBST:
case OP_TRANS:
diff --git a/t/lib/croak/op b/t/lib/croak/op
index cd3a6544e3..439878959e 100644
--- a/t/lib/croak/op
+++ b/t/lib/croak/op
@@ -65,6 +65,54 @@ my main $f;
EXPECT
No such class field "c" in variable $f of type main at - line 3.
########
+# NAME Num-specific &= on @array
+use feature 'bitwise';
+@a &= 1;
+EXPECT
+The bitwise feature is experimental at - line 2.
+Can't modify array dereference in numeric bitwise and (&) at - line 2, near "1;"
+Execution of - aborted due to compilation errors.
+########
+# NAME Num-specific |= on @array
+use feature 'bitwise';
+@a |= 1;
+EXPECT
+The bitwise feature is experimental at - line 2.
+Can't modify array dereference in numeric bitwise or (|) at - line 2, near "1;"
+Execution of - aborted due to compilation errors.
+########
+# NAME Num-specific ^= on @array
+use feature 'bitwise';
+@a ^= 1;
+EXPECT
+The bitwise feature is experimental at - line 2.
+Can't modify array dereference in numeric bitwise xor (^) at - line 2, near "1;"
+Execution of - aborted due to compilation errors.
+########
+# NAME &.= on @array
+use feature 'bitwise';
+@a &.= 1;
+EXPECT
+The bitwise feature is experimental at - line 2.
+Can't modify array dereference in string bitwise and (&.) at - line 2, near "1;"
+Execution of - aborted due to compilation errors.
+########
+# NAME |.= on @array
+use feature 'bitwise';
+@a |.= 1;
+EXPECT
+The bitwise feature is experimental at - line 2.
+Can't modify array dereference in string bitwise or (|.) at - line 2, near "1;"
+Execution of - aborted due to compilation errors.
+########
+# NAME ^.= on @array
+use feature 'bitwise';
+@a ^.= 1;
+EXPECT
+The bitwise feature is experimental at - line 2.
+Can't modify array dereference in string bitwise xor (^.) at - line 2, near "1;"
+Execution of - aborted due to compilation errors.
+########
# NAME Can't declare conditional
my($a?$b:$c)
EXPECT