summaryrefslogtreecommitdiff
path: root/lib/overload.t
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2014-08-24 22:12:52 -0700
committerFather Chrysostomos <sprout@cpan.org>2014-08-24 22:49:19 -0700
commiteff754733a9f186c56767f2a49ab50e67600d3de (patch)
treea065c666cb9ba1391ff73a5b03371390e412c399 /lib/overload.t
parent2445f2a6dfe26f6392ad410f27e34b382631a9db (diff)
downloadperl-eff754733a9f186c56767f2a49ab50e67600d3de.tar.gz
Remove compile-time checking of rv2?v with const kid
There was code in op.c:ck_rvconst (which runs when creating a derefer- ence op, such as rv2sv, rv2av, etc.) that would check that a constant kid holding a reference pointed to something of the right type. It failed to take overloading into account. The result was that these lines would fail to compile: constant_reference_to_hash_with_coderef_overloading->(); constant_reference_to_sub_with_hashref_overloading->{key}; constant_reference_to_sub_with_arrayref_overloading->[0]; constant_reference_to_sub_with_scalarref_overloading->$*; even though they should work. Since the overloadedness could change any time, even checking for that in op.c is incorrect. The only correct fix is to remove this compile- time check. If something naughty gets through, it will be caught at run time. This fixes bugs #122607 and #69456.
Diffstat (limited to 'lib/overload.t')
-rw-r--r--lib/overload.t19
1 files changed, 18 insertions, 1 deletions
diff --git a/lib/overload.t b/lib/overload.t
index d89ec2a510..2371c71a3f 100644
--- a/lib/overload.t
+++ b/lib/overload.t
@@ -48,7 +48,7 @@ package main;
$| = 1;
BEGIN { require './test.pl' }
-plan tests => 5194;
+plan tests => 5198;
use Scalar::Util qw(tainted);
@@ -2730,6 +2730,23 @@ EOF
pass("RT 121362");
}
+package refsgalore {
+ use overload
+ '${}' => sub { \42 },
+ '@{}' => sub { [43] },
+ '%{}' => sub { { 44 => 45 } },
+ '&{}' => sub { sub { 46 } };
+}
+{
+ use feature 'postderef';
+ no warnings 'experimental::postderef';
+ tell myio; # vivifies *myio{IO} at compile time
+ use constant ioref => bless *myio{IO}, refsgalore::;
+ is ioref->$*, 42, '(overloaded constant that is not a scalar ref)->$*';
+ is ioref->[0], 43, '(ovrld constant that is not an array ref)->[0]';
+ is ioref->{44}, 45, "(ovrld const that is not a hash ref)->{key}";
+ is ioref->(), 46, '(overloaded constant that is not a sub ref)->()';
+}
{ # undefining the overload stash -- KEEP THIS TEST LAST
package ant;