New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
perl 5.8.x bug: overloaded 'eq' does not work with 'nomethod' #8784
Comments
From @cpansproutIf a package uses overloading with the 'nomethod' symbol and the This program prints 1, though it should print nothing: This program prints nothing, though it should print 1: And this program #!/usr/bin/perl -lw prints: Flags: Site configuration information for perl v5.8.8: Configured by neo at Tue Jan 9 16:06:53 PST 2007. Summary of my perl5 (revision 5 version 8 subversion 8) configuration: Locally applied patches: @INC for perl v5.8.8: Environment for perl v5.8.8: |
From rick@bort.caOn Feb 19 2007, Father Chrysostomos wrote:
This happens because when a method for "eq" can't be found, perl looks What should happen when the "cmp" method is not found is that the Patch attached. -- |
From rick@bort.ca41546.patchdiff -pruN perl-current/gv.c perl-current-dev/gv.c
--- perl-current/gv.c 2007-02-18 14:41:07.000000000 -0500
+++ perl-current-dev/gv.c 2007-02-21 15:43:40.000000000 -0500
@@ -1871,6 +1871,19 @@ Perl_amagic_call(pTHX_ SV *left, SV *rig
} else {
not_found: /* No method found, either report or croak */
switch (method) {
+ case lt_amg:
+ case le_amg:
+ case gt_amg:
+ case ge_amg:
+ case eq_amg:
+ case ne_amg:
+ case slt_amg:
+ case sle_amg:
+ case sgt_amg:
+ case sge_amg:
+ case seq_amg:
+ case sne_amg:
+ postpr = 0; break;
case to_sv_amg:
case to_av_amg:
case to_hv_amg:
diff -pruN perl-current/lib/overload.t perl-current-dev/lib/overload.t
--- perl-current/lib/overload.t 2006-11-24 10:08:50.000000000 -0500
+++ perl-current-dev/lib/overload.t 2007-02-21 16:39:06.000000000 -0500
@@ -47,7 +47,7 @@ sub numify { 0 + "${$_[0]}" } # Not need
package main;
$| = 1;
-use Test::More tests => 512;
+use Test::More tests => 522;
$a = new Oscalar "087";
@@ -1286,3 +1286,50 @@ foreach my $op (qw(<=> == != < <= > >=))
$c |= $d;
is($c->val, 'c | d', "overloaded |= (by fallback) works");
}
+
+{
+ # comparison operators with nomethod
+ my $warning = "";
+ my $method;
+
+ package nomethod_false;
+ use overload nomethod => sub { $method = 'nomethod'; 0 };
+
+ package nomethod_true;
+ use overload nomethod => sub { $method= 'nomethod'; 'true' };
+
+ package main;
+ local $^W = 1;
+ local $SIG{__WARN__} = sub { $warning = $_[0] };
+
+ my $f = bless [], 'nomethod_false';
+ ($warning, $method) = ("", "");
+ is($f eq 'whatever', 0, 'nomethod makes eq return 0');
+ is($method, 'nomethod');
+
+ my $t = bless [], 'nomethod_true';
+ ($warning, $method) = ("", "");
+ is($t eq 'whatever', 'true', 'nomethod makes eq return "true"');
+ is($method, 'nomethod');
+ is($warning, "", 'nomethod eq need not return number');
+
+ eval q{
+ package nomethod_false;
+ use overload cmp => sub { $method = 'cmp'; 0 };
+ };
+ $f = bless [], 'nomethod_false';
+ ($warning, $method) = ("", "");
+ ok($f eq 'whatever', 'eq falls back to cmp (nomethod not called)');
+ is($method, 'cmp');
+
+ eval q{
+ package nomethod_true;
+ use overload cmp => sub { $method = 'cmp'; 'true' };
+ };
+ $t = bless [], 'nomethod_true';
+ ($warning, $method) = ("", "");
+ ok($t eq 'whatever', 'eq falls back to cmp (nomethod not called)');
+ is($method, 'cmp');
+ like($warning, qr/isn't numeric/, 'cmp should return number');
+
+}
|
The RT System itself - Status changed from 'new' to 'open' |
@rgs - Status changed from 'open' to 'resolved' |
From @rgarciaOn 21/02/07, Rick Delaney <rick@bort.ca> wrote:
Thanks, applied as change #30383. |
Migrated from rt.perl.org#41546 (status was 'resolved')
Searchable as RT41546$
The text was updated successfully, but these errors were encountered: