Skip Menu |

This queue is for tickets about the autovivification CPAN distribution.

Report information
The Basics
Id: 120553
Status: rejected
Priority: 0/
Queue: autovivification

People
Owner: Nobody in particular
Requestors: therealryan [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: Unexpected autovivification of sub arguments
Date: Wed, 08 Mar 2017 09:26:11 +0000
To: bug-autovivification [...] rt.cpan.org
From: Ryan McNally <therealryan [...] gmail.com>
Howdy System details: Perl 5.20.2 on Debian Jessie. I would expect the following program to die on line 19, but it doesn't: use 5.014; use strict; use warnings; no autovivification; { my $foo = undef; my $thing = $foo->{bar}; # this does not die, as expected die if defined $foo; } { my $foo = undef; do_nothing( $foo->{bar} ); # I would expect this to die, but it doesn't - $foo has been autovivified die unless defined $foo; } sub do_nothing { return undef; } If this is expected behaviour then it seems like a notable caveat to the purpose of the 'no autovivification' pragma, and should be documented as such. Thanks!
Le Mer 08 Mar 2017 04:26:39, therealryan@gmail.com a écrit : Show quoted text
> Howdy > > System details: Perl 5.20.2 on Debian Jessie. > > I would expect the following program to die on line 19, but it doesn't: > > use 5.014; > use strict; > use warnings; > no autovivification; > > { > my $foo = undef; > my $thing = $foo->{bar}; > > # this does not die, as expected > die if defined $foo; > } > > { > my $foo = undef; > do_nothing( $foo->{bar} ); > > # I would expect this to die, but it doesn't - $foo has been autovivified > die unless defined $foo; > } > > sub do_nothing { > return undef; > } > > If this is expected behaviour then it seems like a notable caveat to the > purpose of the 'no autovivification' pragma, and should be documented as > such. > > Thanks!
Hello, This behaviour is expected, and nothing can reasonably be done in autovivification.pm to alter it. Since Perl subroutine arguments are passed by alias, the argument list is tagged as "modifiable" by the perl interpreter, in case your do_nothing() sub assigns something to its argument. There's no way for perl to know at compile-time whether that's the case or not. The same reasoning holds for loops. You can forbid this kind of autovivification with the 'store' option, but it is generally very restrictive so I advise against using it. This is the place in the documentation where these kinds of modifiable idioms are listed, but I agree that it is probably not clear enough. However, I don't consider this behaviour to be a caveat of this pragma, since it is consistent with what constructs the Perl language tags as modifiable. I'll think of something for the next release (no timeline implied). Vincent
Subject: Re: [rt.cpan.org #120553] Unexpected autovivification of sub arguments
Date: Mon, 13 Mar 2017 11:45:40 +0000
To: bug-autovivification [...] rt.cpan.org
From: Ryan McNally <therealryan [...] gmail.com>
Aye, that makes sense. Thanks for your time! On Mon, 13 Mar 2017 at 11:37 Vincent Pit via RT < bug-autovivification@rt.cpan.org> wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=120553 > > > Le Mer 08 Mar 2017 04:26:39, therealryan@gmail.com a écrit :
> > Howdy > > > > System details: Perl 5.20.2 on Debian Jessie. > > > > I would expect the following program to die on line 19, but it doesn't: > > > > use 5.014; > > use strict; > > use warnings; > > no autovivification; > > > > { > > my $foo = undef; > > my $thing = $foo->{bar}; > > > > # this does not die, as expected > > die if defined $foo; > > } > > > > { > > my $foo = undef; > > do_nothing( $foo->{bar} ); > > > > # I would expect this to die, but it doesn't - $foo has been
> autovivified
> > die unless defined $foo; > > } > > > > sub do_nothing { > > return undef; > > } > > > > If this is expected behaviour then it seems like a notable caveat to the > > purpose of the 'no autovivification' pragma, and should be documented as > > such. > > > > Thanks!
> > Hello, > > This behaviour is expected, and nothing can reasonably be done in > autovivification.pm to alter it. Since Perl subroutine arguments are > passed by alias, the argument list is tagged as "modifiable" by the perl > interpreter, in case your do_nothing() sub assigns something to its > argument. There's no way for perl to know at compile-time whether that's > the case or not. The same reasoning holds for loops. > > You can forbid this kind of autovivification with the 'store' option, but > it is generally very restrictive so I advise against using it. This is the > place in the documentation where these kinds of modifiable idioms are > listed, but I agree that it is probably not clear enough. However, I don't > consider this behaviour to be a caveat of this pragma, since it is > consistent with what constructs the Perl language tags as modifiable. I'll > think of something for the next release (no timeline implied). > > > Vincent >