Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent autovivification #15005

Closed
p5pRT opened this issue Oct 23, 2015 · 5 comments
Closed

Inconsistent autovivification #15005

p5pRT opened this issue Oct 23, 2015 · 5 comments

Comments

@p5pRT
Copy link

p5pRT commented Oct 23, 2015

Migrated from rt.perl.org#126432 (status was 'rejected')

Searchable as RT126432$

@p5pRT
Copy link
Author

p5pRT commented Oct 23, 2015

From hjp@hjp.at

Consider the attached test script.

It tries to use a non-existing node in a (deep) hash as an arrayref. First in the condition of a for loop​:

for my $node (@​{ $cache->{$facttablename}{$parent_selection_key}{$relevant_roles}{path}

Then in list context in an expression​:

...
  = [
  @​{ $cache->{$facttablename}{$parent_selection_key}{$relevant_roles}{path} },
  ...
  ];

The first one works (autovivifying ...->{path} to []), the second dies with the message

Can't use an undefined value as an ARRAY reference at ./foo line 36

I don't see a meaningful difference between those two use cases. Either both should autovivify or both should die.

@p5pRT
Copy link
Author

p5pRT commented Oct 23, 2015

From hjp@hjp.at

foo

@p5pRT
Copy link
Author

p5pRT commented Oct 25, 2015

From @iabyn

On Fri, Oct 23, 2015 at 01​:54​:33AM -0700, Peter J. Holzer wrote​:

# New Ticket Created by Peter J. Holzer
# Please include the string​: [perl #126432]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl5/Ticket/Display.html?id=126432 >

Consider the attached test script.

It tries to use a non-existing node in a (deep) hash as an arrayref. First in the condition of a for loop​:

for my $node (@​{ $cache->{$facttablename}{$parent_selection_key}{$relevant_roles}{path}

Then in list context in an expression​:

...
= [
@​{ $cache->{$facttablename}{$parent_selection_key}{$relevant_roles}{path} },
...
];

The first one works (autovivifying ...->{path} to []), the second dies with the message

Can't use an undefined value as an ARRAY reference at ./foo line 36

I don't see a meaningful difference between those two use cases. Either
both should autovivify or both should die.

Using a reduced version of your example​:

  use strict;
  my $r = {};
  for my $node (@​{ $r->{foo} }) {}
  () = @​{ $r->{bar} };

In the for loop, the array dereference is in lvalue context, since $node
becomes a writeable alias to each element in @​{$r->foo} in turn.

In the empty list assignment, the array derefernce is in rvalue context,
ans so doesn't auto-vivify.

It's basically the same as

  @​{ $r->{foo} } = @​a; # lvalue
  @​a = @​{ $r->{bar} }; # rvalue

--
Never do today what you can put off till tomorrow.

@p5pRT
Copy link
Author

p5pRT commented Oct 25, 2015

The RT System itself - Status changed from 'new' to 'open'

@p5pRT p5pRT closed this as completed Dec 3, 2015
@p5pRT
Copy link
Author

p5pRT commented Dec 3, 2015

@iabyn - Status changed from 'open' to 'rejected'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant