diff options
author | Nicholas Clark <nick@ccl4.org> | 2004-07-14 15:36:57 +0000 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2004-07-14 15:36:57 +0000 |
commit | 0bdaccee393e6b53324e029b6bf5b646d5d93331 (patch) | |
tree | 462bb634a6416308e616ab5ef8994a59bd172a17 /lib | |
parent | 4d46db716459905a58c7a86181b69d8dadaf4951 (diff) | |
download | perl-0bdaccee393e6b53324e029b6bf5b646d5d93331.tar.gz |
Numeric comparison operators mustn't compare addresses of references
that are overloaded.
p4raw-id: //depot/perl@23106
Diffstat (limited to 'lib')
-rw-r--r-- | lib/overload.t | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/lib/overload.t b/lib/overload.t index 4184e23794..519c6d8810 100644 --- a/lib/overload.t +++ b/lib/overload.t @@ -57,16 +57,20 @@ sub test { $comment = " # " . $_ [2] if @_ > 2; if ($_[0] eq $_[1]) { print "ok $test$comment\n"; + return 1; } else { $comment .= ": '$_[0]' ne '$_[1]'"; print "not ok $test$comment\n"; + return 0; } } else { if (shift) { print "ok $test\n"; + return 1; } else { print "not ok $test\n"; - } + return 0; + } } } @@ -1123,5 +1127,37 @@ test (overload::StrVal(qr/a/) =~ /^Regexp=SCALAR\(0x[0-9a-f]+\)$/); test($out2, 17, "#24313"); # 232 } +{ + package Numify; + use overload (qw(0+ numify fallback 1)); + + sub new { + my $val = $_[1]; + bless \$val, $_[0]; + } + + sub numify { ${$_[0]} } +} + +# These are all check that overloaded values rather than reference addressess +# are what is getting tested. +my ($two, $one, $un, $deux) = map {new Numify $_} 2, 1, 1, 2; +my ($ein, $zwei) = (1, 2); + +my %map = (one => 1, un => 1, ein => 1, deux => 2, two => 2, zwei => 2); +foreach my $op (qw(<=> == != < <= > >=)) { + foreach my $l (keys %map) { + foreach my $r (keys %map) { + my $ocode = "\$$l $op \$$r"; + my $rcode = "$map{$l} $op $map{$r}"; + + my $got = eval $ocode; + die if $@; + my $expect = eval $rcode; + die if $@; + test ($got, $expect, $ocode) or print "# $rcode\n"; + } + } +} # Last test is: -sub last {232} +sub last {484} |