[Gambas-user] Nasty bug in "With" instruction!

Jussi Lahtinen jussi.lahtinen at ...626...
Mon Apr 20 16:37:57 CEST 2009


Thanks!
OK, I have to check my code for this... in vb this works different way.
Thought I don't know how exactly. In vb WITH instruction (properly
placed) speeded up code,
and code I used as example worked. Maybe it used tmp like in Gambas,
but it did this also:

Code:

With var
.y = 0
var = funcx()

Maybe equivalent to:

tmp = var
tmp.y = 0
tmp =  funcx()

So, maybe from "WITH xyz", "xyz" where searched from within WITH -->
END WITH, and replaced to tmp.
That would be nice to see in Gambas!


Jussi
P.S. Don't get me wrong, I'm very pleased that I don't have to use M$
products anymore! Gambas is GREAT!




2009/4/20 Benoît Minisini <gambas at ...1...>:
>> Some more testing...
>> With this code:
>>
>> With tmp
>>   .y = 0
>>   tmp = funcx()
>>     With tmp ' Extra with instruction.
>>     Debug .y
>>     Debug tmp.y
>>     End With
>> End With
>>
>> Or with this:
>>
>>  With tmp
>>   .y = 0
>>   funcx2(tmp) ' By reference (unfortunately this solution doesn't fit
>> to my code).
>>    Debug .y
>>    Debug tmp.y
>>  End With
>>
>>   Public Sub funcx2(test as Class1)
>>   test.y = 1
>>   End
>>
>> Result is what is expected!
>>
>> I tried to look at the gambas source code to figure out what is
>> wrong... beats me up.
>> But maybe the problem is in how archiver or interpreter handles "tmp =
>> ...". Extra "with" instruction is workaround, but it's little troublesome
>> to find where it is needed.
>> And when "tmp = funcx()" is in "if then else" structure, it is very
>> troublesome! Maybe I need temporarily to get rid of "with" instructions!
>> But I hope it is easy to fix!
>>
>> Regards,
>> Jussi
>>
>> On Thu, Apr 16, 2009 at 16:17, Jussi Lahtinen <jussi.lahtinen at ...626...>
> wrote:
>> > Hi!
>> > Confirmed on Gambas2 and Gambas3.
>> >
>> > Code:
>> >
>> > Dim tmp As New Class1
>> >
>> > With tmp
>> >  .y = 0
>> >  tmp = funcx()
>> >  Debug .y
>> >  Debug tmp.y
>> > End With
>> >
>> >
>> > Public Function funcx() As Class1
>> > Dim test As New Class1
>> >
>> > test.y = 1
>> >
>> > Return test
>> > End
>> >
>> >
>> > Output of debug is;
>> > 0
>> > 1
>> >
>> > I think .y and tmp.y should be same!
>> >
>> > Regards,
>> > Jussi
>>
>
> WITH is actually managed at runtime, not at compile time.
>
> I mean:
>
> WITH var
>  .x = ...
>  .y = ...
> END WITH
>
> is equivalent to:
>
> tmp = var
> tmp.x = ...
> tmp.y = ...
>
> and not to:
>
> var.x = ...
> var.y = ...
>
> So, by changing the value of tmp inside the WITH instruction, you are not
> changing the object WITH works on!
>
> Regards,
>
>
> --
> Benoît
>
> ------------------------------------------------------------------------------
> Stay on top of everything new and different, both inside and
> around Java (TM) technology - register by April 22, and save
> $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
> 300 plus technical and hands-on sessions. Register today.
> Use priority code J9JMT32. http://p.sf.net/sfu/p
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>




More information about the User mailing list