bmx-ng / bcc

A next-generation bcc parser for BlitzMax
zlib License
33 stars 12 forks source link

[collections.mod] TLinkedList ToArray bug #607

Closed thareh closed 1 year ago

thareh commented 2 years ago

Hey,

Sometimes the ToArray() method seems to bug out.

Framework BRL.Blitz
Import BRL.Collections
Import BRL.StandardIO
Import BRL.Random

SeedRnd(MilliSecs())

Local list:TLinkedList<Int> = New TLinkedList<Int>()

For Local i:Int = 0 To 9999
    list.AddLast(Rand(0, 9999))
Next

Local arr:Int[] = list.ToArray()

Print list.count()
Print arr.length

Print list.LastValue()
Print arr[arr.length-1]

Thanks, -- Thareh

thareh commented 2 years ago

Seems to be related to bmx-ng/bcc#606, the values with 0 gets skipped.

thareh commented 2 years ago

Moving the ToArray function outside of the TLinkedList type seems to work.

Framework BRL.Blitz
Import BRL.Collections
Import BRL.StandardIO
Import BRL.Random

SeedRnd(MilliSecs())

Local list:TLinkedList<Int> = New TLinkedList<Int>()

For Local i:Int = 0 To 9
    list.AddLast(Rand(0,1))
Next

'Local arr:Int[] = list.ToArray()

Local arr:Int[list.Count()]
Local i:Int
For Local elem:Int = EachIn list
    arr[i] = elem
    i :+ 1
Next

Print list.count()
Print list.LastValue()

Print

For Local val:Int = EachIn list
    Print val
Next

Print

Print arr.length
Print arr[arr.length-1]

Print

For Local val:Int = EachIn arr
    Print val
Next