summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2011-07-10 04:35:36 -0500
committerJesse Luehrs <doy@tozt.net>2011-07-10 04:35:36 -0500
commit53099361ccac273f69fea1f7739d884db52bbf1a (patch)
tree4d675e6717ee923f393e5ee180aecfdd6746c74b
parentd44ae92419b4c41652c80d671f78da79d9ab3028 (diff)
downloadsmartmatch-53099361ccac273f69fea1f7739d884db52bbf1a.tar.gz
smartmatch-53099361ccac273f69fea1f7739d884db52bbf1a.zip
hack around a parsing bug in earlier perls
this may preclude us from being able to implement bug-compatible engines from both 5.12 and 5.14, but... shrug, can deal with that later if we decide we care
-rw-r--r--smartmatch.xs40
-rw-r--r--t/slices.t21
2 files changed, 61 insertions, 0 deletions
diff --git a/smartmatch.xs b/smartmatch.xs
index a639242..5fa0280 100644
--- a/smartmatch.xs
+++ b/smartmatch.xs
@@ -51,6 +51,46 @@ smartmatch_cb(pTHX_ OP *o, void *user_data)
o->op_flags &= ~OPf_KIDS;
op_free(o);
+/* array slices used to parse incorrectly (perl RT#77468),
+ * fix (hack) this up */
+#if PERL_VERSION < 14
+ if (left->op_type == OP_ASLICE) {
+ OP *sib;
+ sib = left->op_sibling;
+ left->op_flags &= ~OPf_WANT_SCALAR;
+ left->op_flags |= OPf_WANT_LIST
+ | OPf_PARENS
+ | OPf_REF
+ | OPf_MOD
+ | OPf_STACKED
+ | OPf_SPECIAL;
+ left->op_sibling = NULL;
+ left = newLISTOP(OP_ANONLIST,
+ OPf_WANT_SCALAR|OPf_SPECIAL,
+ newOP(OP_PUSHMARK, 0),
+ left);
+ left->op_sibling = sib;
+ }
+ if (right->op_type == OP_ASLICE) {
+ OP *sib;
+ sib = right->op_sibling;
+ right->op_flags &= ~OPf_WANT_SCALAR;
+ right->op_flags |= OPf_WANT_LIST
+ | OPf_PARENS
+ | OPf_REF
+ | OPf_MOD
+ | OPf_STACKED
+ | OPf_SPECIAL;
+ right->op_sibling = NULL;
+ right = newLISTOP(OP_ANONLIST,
+ OPf_WANT_SCALAR|OPf_SPECIAL,
+ newOP(OP_PUSHMARK, 0),
+ right);
+ right->op_sibling = sib;
+ left->op_sibling = right;
+ }
+#endif
+
cb_op = newCVREF(0, newSVOP(OP_CONST, 0, newSVsv(*cb)));
list = newLISTOP(OP_LIST, 0, left, right);
new = newUNOP(OP_ENTERSUB, OPf_STACKED,
diff --git a/t/slices.t b/t/slices.t
new file mode 100644
index 0000000..584dd43
--- /dev/null
+++ b/t/slices.t
@@ -0,0 +1,21 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More;
+
+my @nums = (1..10);
+
+{
+ use smartmatch sub {
+ return ref $_[0] eq 'ARRAY'
+ && ref $_[1] eq 'ARRAY'
+ && @{ $_[0] } == @{ $_[1] };
+ };
+ ok(@nums[0..-1] ~~ []);
+ ok(!(@nums[0..1] ~~ [0..2]));
+ ok(@nums[0..4] ~~ [1..5]);
+ ok(!(undef ~~ @nums[0..-1]));
+ ok(!(@nums[0..1] ~~ 2));
+}
+
+done_testing;