Skip Menu |
Report information
Id: 132053
Status: open
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: tomentiruran [at] gmail.com
Cc:
AdminCc:

Severity: (no value)
Tag: Bug
Platform: (no value)
Patch Status: (no value)
VM: (no value)



Subject: [BUG] Autovivification on element with [] or {} as default causes "secret" keys
From: Andrew Buchanan <tomentiruran [...] gmail.com>
Date: Sun, 10 Sep 2017 10:53:26 +0800
To: rakudobug [...] perl.org
Download (untitled) / with headers
text/plain 303b
> my @h is default([])
[]
> @h[0].push: 3
[3]
> @h
[]
> @h[0]
[3]

> my %h is default({})
{}
> %h<a><b> = 3
3
> %h
{}
> %h<a>
{b => 3}

The array/hash variable's default is an empty array/hash literal. If an element is autovivified, it can be accessed directly, but isn’t findable from the variable.

Heh.

FWIW we had this since forever: https://gist.github.com/Whateverable/78168042a011e01fc768c042b0d91898

On 2017-09-09 19:53:53, tomentiruran@gmail.com wrote:
Show quoted text
> > my @h is default([])
> []
> > @h[0].push: 3
> [3]
> > @h
> []
> > @h[0]
> [3]
>
> > my %h is default({})
> {}
> > %h<a><b> = 3
> 3
> > %h
> {}
> > %h<a>
> {b => 3}
>
> The array/hash variable's default is an empty array/hash literal. If
> an element is autovivified, it can be accessed directly, but isn’t
> findable from the variable.


RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 742b
On Sat, 09 Sep 2017 19:53:53 -0700, tomentiruran@gmail.com wrote: Show quoted text
> > my @h is default([])
> []
> > @h[0].push: 3
> [3]
> > @h
> []
> > @h[0]
> [3] >
> > my %h is default({})
> {}
> > %h<a><b> = 3
> 3
> > %h
> {}
> > %h<a>
> {b => 3} > > The array/hash variable's default is an empty array/hash literal. If > an element is autovivified, it can be accessed directly, but isn’t > findable from the variable.
While I suspect this can be fixed (and is missing setup of the auto-viv callback on the codepath for setting up a default), note that `is default` is a trait, it is evaluated at compile time. Thus there is one single array that will be shared globally and assigned into all elements, which probably isn't what you wanted. /jnthn


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org