From: Rick Delaney Date: Sun, 7 Oct 2007 22:37:01 +0000 (-0400) Subject: Re: [perl #46011] [RESOLVED] overload "0+" doesn't handle integer results X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e28bb1d52bee845e0aab3d253cd27698a545c674;p=p5sagit%2Fp5-mst-13.2.git Re: [perl #46011] [RESOLVED] overload "0+" doesn't handle integer results Message-ID: <20071008023701.GI29047@bort.ca> p4raw-id: //depot/perl@32062 --- diff --git a/lib/overload.t b/lib/overload.t index 9b17923..09809d5 100644 --- a/lib/overload.t +++ b/lib/overload.t @@ -47,7 +47,7 @@ sub numify { 0 + "${$_[0]}" } # Not needed, additional overhead package main; $| = 1; -use Test::More tests => 535; +use Test::More tests => 536; $a = new Oscalar "087"; @@ -1383,6 +1383,8 @@ foreach my $op (qw(<=> == != < <= > >=)) { use overload "0+" => sub { $_[0][0]++; $_[0] }; package numify_other; use overload "0+" => sub { $_[0][0]++; $_[0][1] = bless [], 'numify_int' }; + package numify_by_fallback; + use overload "-" => sub { 1 }, fallback => 1; package main; my $o = bless [], 'numify_int'; @@ -1399,4 +1401,7 @@ foreach my $op (qw(<=> == != < <= > >=)) { is(int($s), 42, 'numifies to numification of other object'); is($s->[0], 1, 'int() numifies once when returning other object'); is($s->[1][0], 1, 'returned object numifies too'); + + my $m = bless $aref, 'numify_by_fallback'; + is(int($m), $num_val, 'numifies to usual reference value'); } diff --git a/pp.c b/pp.c index c916bf6..3e22feb 100644 --- a/pp.c +++ b/pp.c @@ -2883,6 +2883,8 @@ PP(pp_int) while (SvAMAGIC(sv)) { SV *tsv = AMG_CALLun(sv,numer); + if (!tsv) + break; if (SvROK(tsv) && SvRV(tsv) == SvRV(sv)) { SETi(PTR2IV(SvRV(sv))); RETURN;