develooper Front page | perl.perl5.porters | Postings from February 2021

Re: Blessed objects are `isa` their reftype

Thread Previous | Thread Next
From:
Yuki Kimoto
Date:
February 18, 2021 02:04
Subject:
Re: Blessed objects are `isa` their reftype
Message ID:
CAExogxMwx1KVWWVs-bmKhQeEKvQS63W32AFNgY5nAby4pQqYkA@mail.gmail.com
Paul

I have a question.

If isa operator

is the following implementation,

  Scalar::Util::blessed $obj && $obj->isa('MyArray::Class')

Is it different from what you want?





2021年2月16日(火) 21:09 Paul "LeoNerd" Evans <leonerd@leonerd.org.uk>:

> There is an odd asymmetry with isa when testing if an object is derived
> from its reference type:
>
>   my $aref = [ 1, 2, 3 ];
>   $aref isa ARRAY             # is false
>
>   my $aobj = bless [ 5, 6, 7 ], "MyArray::Class";
>   $aobj isa MyArray::Class    # is true
>   $aobj isa ARRAY             # is true(!)
>
> As further explained by documentation I have just added in my new
> branch https://github.com/Perl/perl5/tree/leonerd/doc-isa
>
>   This is done in order to preserve the equivalence to the
>   C<UNIVERSAL::isa> method, which would also yield true in the same
>   circumstance. Despite this, it is not true that C<$aobj> would
>   consider methods in the C<ARRAY::> package as part of its method
>   resolution order.
>
> I'm not terribly comfortable with this situation, but annoyingly any
> other solution feels worse:
>
>  1. `isa` could warn (or croak?) on attempts to test the known all-caps
>     reftype names (which are NOT perl packages)
>
>  2. `isa` could specifically omit these (and thus break equivalence
>     with the `->isa` method)
>
> Or something else.
>
> If we accept that the current behaviour is the "least bad" of them and
> we don't want to change it, then perhaps we can decide to
> de-experimentalize this operator now it's been sitting unchanged for
> all of 5.32, in time for a proper addition into 5.34.
>
> Thoughts, anyone?
>
> (cross-posted to github https://github.com/Perl/perl5/issues/18585)
>
> --
> Paul "LeoNerd" Evans
>
> leonerd@leonerd.org.uk      |  https://metacpan.org/author/PEVANS
> http://www.leonerd.org.uk/  |  https://www.tindie.com/stores/leonerd/
>

Thread Previous | Thread Next


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