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

Blessed objects are `isa` their reftype

Thread Next
From:
Paul "LeoNerd" Evans
Date:
February 16, 2021 12:09
Subject:
Blessed objects are `isa` their reftype
Message ID:
20210216120857.483d3ad1@shy.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 Next


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