Navigation Menu

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

Wrong array length when Mu elements and delete interact in Rakudo #3044

Closed
p6rt opened this issue Feb 8, 2013 · 9 comments
Closed

Wrong array length when Mu elements and delete interact in Rakudo #3044

p6rt opened this issue Feb 8, 2013 · 9 comments

Comments

@p6rt
Copy link

p6rt commented Feb 8, 2013

Migrated from rt.perl.org#116695 (status was 'resolved')

Searchable as RT116695$

@p6rt
Copy link
Author

p6rt commented Feb 8, 2013

From @masak

<pmurias> I have found a rakudo bug
<pmurias> my $foo = [0,1,2,3,4];say $foo.elems;$foo[4] = Mu;$foo[3] =
Mu;say $foo.elems;$foo.delete(4);say $foo.elems;
<masak> r​: my $foo = [0,1,2,3,4];say $foo.elems;$foo[4] = Mu;$foo[3] =
Mu;say $foo.elems;$foo.delete(4);say $foo.elems
<+p6eval> rakudo 4fb07b​: OUTPUT«5␤5␤3␤»
* masak submits rakuodbug
<masak> pmurias++

@p6rt
Copy link
Author

p6rt commented Feb 8, 2013

From @masak

<tadzik> don't know about nqp, but on JVM we keep a constant value in
QRPA which says how many elements are there
<tadzik> it probably needs to be updated when we set Mu somewhere
<moritz> the problem is that if you delete an element that's not the
last, it set to Mu
<moritz> because we don't have an offchannel way to store an array
element as deleted
<pmurias> no
<moritz> no?
<tadzik> we have to settle of something​: do we count the number of
defined elements in the array, or do we count "the longest streak" of
elements?
<pmurias> the problem is that if you delete the last element all the
undefined elements before it get deletedf
<moritz> r​: my @​a = <a b c d>; @​a.delete(2); say @​a.perl
<p6eval> rakudo 4fb07b​: OUTPUT«Array.new("a", "b", Any, "d")␤»
<moritz> tadzik​: or do we simply keep the count separate, and don't do
any magic
<moritz> pmurias​: I'm (nearly) sure there's a spectest that requires
that
<pmurias> r​: class Foo {};my $foo = [0,1,2,3,4];say $foo.elems;$foo[4] =
Foo;$foo[3] = Foo;say $foo.elems;$foo.delete(4);say $foo.elems;
<p6eval> rakudo 4fb07b​: OUTPUT«5␤5␤3␤»
<pmurias> moritz​: it seems to be a bug in the code
<moritz> fwiw I agree that's undesirable
<moritz> but I can't quite imagine that it happened without any
intention
* masak adds this to the ticket
<pmurias> the spec seems to hold an distinction between elements that
aren't in an array and those that are set to an undefined value

@p6rt
Copy link
Author

p6rt commented Feb 8, 2013

@masak - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Oct 8, 2014

From @usev6

It looks like deleting the last element of an array no longer deletes the undefined elements before it​:

my $foo = [0,1,2,3,4]; say $foo.elems; say $foo.perl
5
[0, 1, 2, 3, 4]
$foo[4] = Any; $foo[3] = Any; say $foo.elems; say $foo.perl
5
[0, 1, 2, Any, Any]
$foo[4] :delete; say $foo.elems; say $foo.perl
4
[0, 1, 2, Any]

The same with class Foo​:

class Foo {}; my $foo = [0,1,2,3,4]; $foo[4] = Foo; $foo[3] = Foo; $foo[4] :delete; say $foo.elems; say $foo.perl
4
[0, 1, 2, Foo]

Is that the expected behaviour? The IRC log above expressed same doubts about that.

1 similar comment
@p6rt
Copy link
Author

p6rt commented Oct 8, 2014

From @usev6

It looks like deleting the last element of an array no longer deletes the undefined elements before it​:

my $foo = [0,1,2,3,4]; say $foo.elems; say $foo.perl
5
[0, 1, 2, 3, 4]
$foo[4] = Any; $foo[3] = Any; say $foo.elems; say $foo.perl
5
[0, 1, 2, Any, Any]
$foo[4] :delete; say $foo.elems; say $foo.perl
4
[0, 1, 2, Any]

The same with class Foo​:

class Foo {}; my $foo = [0,1,2,3,4]; $foo[4] = Foo; $foo[3] = Foo; $foo[4] :delete; say $foo.elems; say $foo.perl
4
[0, 1, 2, Foo]

Is that the expected behaviour? The IRC log above expressed same doubts about that.

@p6rt
Copy link
Author

p6rt commented Oct 8, 2014

From @lizmat

On 08 Oct 2014, at 12​:30, Christian Bartolomaeus via RT <bugs-comment@​bugs6.perl.org> wrote​:

It looks like deleting the last element of an array no longer deletes the undefined elements before it​:

my $foo = [0,1,2,3,4]; say $foo.elems; say $foo.perl
5
[0, 1, 2, 3, 4]
$foo[4] = Any; $foo[3] = Any; say $foo.elems; say $foo.perl
5
[0, 1, 2, Any, Any]
$foo[4] :delete; say $foo.elems; say $foo.perl
4
[0, 1, 2, Any]

The same with class Foo​:

class Foo {}; my $foo = [0,1,2,3,4]; $foo[4] = Foo; $foo[3] = Foo; $foo[4] :delete; say $foo.elems; say $foo.perl
4
[0, 1, 2, Foo]

Is that the expected behaviour? The IRC log above expressed same doubts about that.

Setting an array element to Any, is *not* the same as deleting an entry. The proper way to do this is with the :delete adverb​:

$ 6 'my $a; $a[5]=1; say $a.elems; $a[5]​:delete; say $a.elems'
6
0

Liz

@p6rt
Copy link
Author

p6rt commented Oct 9, 2014

From @usev6

Well, this bug is gone, then. I added a test to S32-array/delete.t with the following commit​: Raku/roast@f386c96536

I had (and have) some difficulties to find the references in the spec for the correct behaviour -- especially with regard to the following quotes from an earlier IRC discussion. But that's not directly related to this bug and I'll bring it up on IRC.

<pmurias> the problem is that if you delete the last element all the undefined elements before it get deleted
[...]
<moritz> pmurias​: I'm (nearly) sure there's a spectest that requires that
[...]
<pmurias> the spec seems to hold an distinction between elements that aren't in an array and those that are set to an undefined value

1 similar comment
@p6rt
Copy link
Author

p6rt commented Oct 9, 2014

From @usev6

Well, this bug is gone, then. I added a test to S32-array/delete.t with the following commit​: Raku/roast@f386c96536

I had (and have) some difficulties to find the references in the spec for the correct behaviour -- especially with regard to the following quotes from an earlier IRC discussion. But that's not directly related to this bug and I'll bring it up on IRC.

<pmurias> the problem is that if you delete the last element all the undefined elements before it get deleted
[...]
<moritz> pmurias​: I'm (nearly) sure there's a spectest that requires that
[...]
<pmurias> the spec seems to hold an distinction between elements that aren't in an array and those that are set to an undefined value

@p6rt
Copy link
Author

p6rt commented Oct 9, 2014

@usev6 - Status changed from 'open' to 'resolved'

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