develooper Front page | perl.perl5.porters | Postings from December 2017

[perl #132489] canonical truth values from overloaded predicates

From:
Curtis Jewell via RT
Date:
December 14, 2017 15:54
Subject:
[perl #132489] canonical truth values from overloaded predicates
Message ID:
rt-4.0.24-20445-1513266839-1212.132489-15-0@perl.org
On Wed, 22 Nov 2017 13:52:12 -0800, zefram@fysh.org wrote:
> 
> This is a bug report for perl from zefram@fysh.org,
> generated with the help of perlbug 1.41 running under perl 5.27.6.
> 
> 
> -----------------------------------------------------------------
> [Please describe your issue here]
> 
> Operator overloading methods are allowed to return any value.  Like
> this:
> 
> $ perl -lwe 'package Five { use overload "<" => sub { 5 }; } print
> bless({}, "Five") < 3'
> 5
> 
> It makes sense for operators like "+" to be able to return any value,
> but it doesn't make sense for predicate operators, such as "!" and
> comparisons.  To have these operators sometimes able to return values
> that are not canonical truth values just makes them surprising,
> and interferes with optimisations that we could potentially make.
> Operators that ordinarily return only truth values should canonicalise
> the truth value returned by overload methods.  Note that we already
> have
> such canonicalisation in the tie interfaces, for example for EXISTS in
> the tied hash interface.

The problem is that there are modules (at least one: IO::All) that abuse the fact that overloaded comparators are NOT canonicalized in a useful way.




---
via perlbug:  queue: perl5 status: new
https://rt.perl.org/Ticket/Display.html?id=132489



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About