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

Autovivification on element with [] or {} as default causes "secret" keys #6508

Open
p6rt opened this issue Sep 10, 2017 · 4 comments
Open
Labels

Comments

@p6rt
Copy link

p6rt commented Sep 10, 2017

Migrated from rt.perl.org#132053 (status was 'open')

Searchable as RT132053$

@p6rt
Copy link
Author

p6rt commented Sep 10, 2017

From tomentiruran@gmail.com

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.

@p6rt
Copy link
Author

p6rt commented Sep 10, 2017

From @AlexDaniel

Heh.

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

On 2017-09-09 19​:53​:53, tomentiruran@​gmail.com wrote​:

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.

@p6rt
Copy link
Author

p6rt commented Sep 10, 2017

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

@p6rt
Copy link
Author

p6rt commented Sep 11, 2017

From @jnthn

On Sat, 09 Sep 2017 19​:53​:53 -0700, tomentiruran@​gmail.com wrote​:

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

@p6rt p6rt added the Bug label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant