diff options
author | Father Chrysostomos <sprout@cpan.org> | 2016-05-20 21:55:40 -0700 |
---|---|---|
committer | Steve Hay <steve.m.hay@googlemail.com> | 2017-08-08 17:48:03 +0100 |
commit | 915d6a669585d5e94c5af2e1d2f635883eff7c01 (patch) | |
tree | 14cf89ef710dcaf4b58fe15f4cb7539ee11729e5 | |
parent | cf1efead3fa596a455f799448d561f12007787e1 (diff) | |
download | perl-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.c | 6 | ||||
-rw-r--r-- | t/lib/croak/op | 48 |
2 files changed, 54 insertions, 0 deletions
@@ -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 |