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

Re: Blessed objects are `isa` their reftype

Thread Previous | Thread Next
From:
David Christensen
Date:
February 16, 2021 22:05
Subject:
Re: Blessed objects are `isa` their reftype
Message ID:
26fe9ebd-e09e-b3f9-a196-92b68c664e3a@holgerdanske.com
On 2021-02-16 13:17, Dan Book wrote:
> On Tue, Feb 16, 2021 at 4:14 PM David Christensen <dpchrist@holgerdanske.com>
> wrote:
> 
>> On 2021-02-16 04:09, Paul "LeoNerd" Evans wrote:
>>> 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(!)
>>
>>
>> Please post a valid Perl program that demonstrates your point (e.g.
>> Test::More, ok, TODO).
>>
> 
> The 'isa' feature must be enabled and requires Perl 5.32+.


2021-02-16 14:02:27 dpchrist@f3 ~/sandbox/perl/p5p
$ freebsd-version ; uname -a ; perl -v | head -n 2
12.1-RELEASE-p13
FreeBSD f3.tracy.holgerdanske.com 12.1-RELEASE-p13 FreeBSD 
12.1-RELEASE-p13 GENERIC  amd64

This is perl 5, version 32, subversion 1 (v5.32.1) built for 
amd64-freebsd-thread-multi

2021-02-16 14:02:32 dpchrist@f3 ~/sandbox/perl/p5p
$ nl paul-leonerd-evans-20210216-0409.pl
      1	  my $aref = [ 1, 2, 3 ];
      2	  $aref isa ARRAY             # is false
       	
      3	  my $aobj = bless [ 5, 6, 7 ], "MyArray::Class";
      4	  $aobj isa MyArray::Class    # is true
      5	  $aobj isa ARRAY             # is true(!)

2021-02-16 14:02:42 dpchrist@f3 ~/sandbox/perl/p5p
$ perl -Eisa paul-leonerd-evans-20210216-0409.pl


Better, but I still do not see any output that demonstrates the OP's point.


David

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