google-code-export / gambas

Automatically exported from code.google.com/p/gambas
1 stars 0 forks source link

The Array Base class does not work as expected #175

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
1) Describe the problem.
The Array classes does not follow the inheritance rules. That leads to problems 
when using the Array Base class like this:

2) GIVE THE FOLLOWING INFORMATIONS (if they are appropriate):

Version: TRUNK

3) Provide a little project that reproduces the bug or the crash.
  Dim a As Array
  Dim i As Integer
  For i = 1 To 2
    If i = 1 Then
      a = New Integer[1]
      a[0] = 1
    Else If i = 2 Then
      a = New String[1]
      a[0] = "2"
    End If
    Print a[0] + i 'Will print the address in memory for "2" + i the second time
  Next

Prints:
2
13148466
gbx3: warning: 2 allocation(s) non freed.

Original issue reported on code.google.com by emil.len...@gmail.com on 29 Dec 2011 at 3:51

GoogleCodeExporter commented 9 years ago
Well, that class coming from Gambas 1 should be virtual, because it wasn't 
intended to be used directly!

Some methods do not work anymore because of an optimization in revision #4248. 
These are all methods returning an array element: _get (array accessor), _next 
(array enumeration), Pop.

I have two solutions: removing these methods, or not sharing them with other 
specific array classes and writing specific versions of them.

I have not decided yet. But I must be fast, the release is the day after 
tomorrow!

Original comment by benoit.m...@gmail.com on 29 Dec 2011 at 4:13

GoogleCodeExporter commented 9 years ago
I also first thought that this class was not to be used alone, but then I saw 
it being used like this in ReadArray() and WriteValue() in gb.settings...

Original comment by emil.len...@gmail.com on 29 Dec 2011 at 4:21

GoogleCodeExporter commented 9 years ago
AFAIK, this is the only place I use it, and I don't think I need it.

By the way, I see you looking everywhere in the code, and I would like to thank 
you for all your bug tracking. I am curious: do you do that just for fun? Or do 
you have any specific project with Gambas? Answer me to 
gambas@users.sourceforge.net.

Original comment by benoit.m...@gmail.com on 29 Dec 2011 at 4:34

GoogleCodeExporter commented 9 years ago
It should be fixed in revision #4360. I chose the second solution.

Original comment by benoit.m...@gmail.com on 29 Dec 2011 at 5:01

GoogleCodeExporter commented 9 years ago
Print a.Pop() + i

still does not work as expected, since the interpreter calls the inherited 
method, not the parent method ;)

Original comment by emil.len...@gmail.com on 29 Dec 2011 at 5:16

GoogleCodeExporter commented 9 years ago
OK, it should be really fixed in revision #4361!

Original comment by benoit.m...@gmail.com on 29 Dec 2011 at 9:55