summaryrefslogtreecommitdiff
path: root/t/re/overload.t
diff options
context:
space:
mode:
authorDavid Mitchell <davem@iabyn.com>2013-03-25 17:06:47 +0000
committerDavid Mitchell <davem@iabyn.com>2013-04-12 11:29:54 +0100
commit16cc92aeb437b42b3f141f69d8d60dae5309ec0f (patch)
tree3431a566caad5c9273f2473c92fe6e3a5940b14f /t/re/overload.t
parent5dd442fcfdfbfbdd8bc0fdb52cd98474826ec4fe (diff)
downloadperl-16cc92aeb437b42b3f141f69d8d60dae5309ec0f.tar.gz
regex and overload: unifiy 1 and N arg branches
When compiling a regex, something like /a$b/ that parses two two args, was treated in a different code path than /$a/ say, which is only one arg. In particular the 1-arg code path, where it handled "" overloading, didn't check for a loop (where the ""-sub returns the overloaded object itself) - the N-arg branch did handle that. By unififying the branches, we get that fix for free, and ensure that any future fixes don't have to be applied to two separate branches. Re-indented has been left to the commit that follows this.
Diffstat (limited to 't/re/overload.t')
-rw-r--r--t/re/overload.t20
1 files changed, 20 insertions, 0 deletions
diff --git a/t/re/overload.t b/t/re/overload.t
index 4e99bd3ec6..7f562c02d4 100644
--- a/t/re/overload.t
+++ b/t/re/overload.t
@@ -33,4 +33,24 @@ no warnings 'syntax';
is $1, $TAG, "void context //g against overloaded object";
}
+{
+ # an overloaded stringify returning itself shouldn't loop indefinitely
+
+
+ {
+ package Self;
+ use overload q{""} => sub {
+ return shift;
+ },
+ fallback => 1;
+ }
+
+ my $obj = bless [], 'Self';
+ my $r = qr/$obj/;
+ pass("self object, 1 arg");
+ $r = qr/foo$obj/;
+ pass("self object, 2 args");
+}
+
+
done_testing();