[Lazarus] Bug in cody. Exploding a hanging with block.

ListMember listmember at letterboxes.org
Tue Jun 10 00:08:49 CEST 2014


On 2014-06-09 22:34, Mattias Gaertner wrote:
> On Mon, 09 Jun 2014 21:49:32 +0300
> ListMember <listmember at letterboxes.org> wrote:
>
>> [...]
>> 1) Could there be an option so that cody leaves (within the source
>> itself) a commented-out copy of the block it has altered.
> Feel free to send a patch for that.

I haven't looked at the code but --from what it alredy does-- it looks 
beyond me.

>> This is needed for 2 reasons.
>>
>> a) I have noticed that cody saves a copy of the altered file to disk
>> immediately.
> Huh? Not that I know.

I checked again. You're right it doesn't do that.

>> [...]
>> b) I also noticed that cody works within the active compiler switches
>> ($IFDEF stuff). While this is good, it also means it leaves out the code
>> in the '$ELSE' part. This may/will become problematic when the '$ELSE'
>> becomes active but there's no way to 'explode with' for it.
> Changing the $ELSE part is dangerous, because the context is wrong.
> The parser does not parse structures within $ELSE parts (e.g. with).
> It should warn the user to check carefully those parts.

Warnings would, of course, be useful.

But, for a complex block it will not really help.

This is an example of what I mean:

with something do begin
{$IFDEF FAVORITE_OS}
{a lot of lines}
with somethingelse do begin
         {a lot of lines}
       end;
     {a lot of lines}
   {$ELSE}
{a lot of lines}
with somethingelse do begin
         {a lot of lines}
       end;
     {a lot of lines}
   {$ENDIF}
end;

At the moment, cody does handle all the complexity for the active half 
of that IFDEF but when the ELSE part is active, since we will have lost 
the encapsulating 'with', we will have to copy&paste that from an original.

Obvioulsy, with careful planning it could be done, but there's always 
the possibility for an oversight which would result in 
uncompilable/orphaned code.

I am not, mind you, saying my idea is the best one (I don't even know if 
it could be implemented); I am merely trying to highlight a potetial 
pitfall.

How about shifting a copy of the 'with' line to inside these IFDEF's, 
such as:

{$IFDEF FAVORITE_OS}
{code which 'with's have been exploded.}
   {$ELSE}
with something do begin
{a lot of lines}
with somethingelse do begin
           {a lot of lines}
         end;
       {a lot of lines}
     end;
   {$ENDIF}

IOW, when the time comes for the ELSE part, all the information is there 
and it compiles even without exploding the 'with's.




More information about the Lazarus mailing list