Here are two situations that expose the bug:
1) The first virtual block has the restore state corrupted by the 'end if'
VAR = 0
org '0'
display $ ;<--- '0'
if VAR = VAR
virtual at '1'
display $ ;<--- '1'
virtual at '2'
display $ ;<--- '2'
end if ;return state of first virtual is corrupted here
if VAR = VAR
display $ ;<--- '2'
end virtual
display $ ;<--- '1'
end virtual ;wrong state is restored here
end if
display $ ;<--- '1'
2) The IF state is corrupted by the 'end virtual'
VAR = 0
org '0'
virtual at '1'
display $ ;<--- '1'
if VAR = VAR
if VAR <> VAR
else
display $ ;<--- '1'
end virtual ;state of first 'if' block is corrupted here
display $ ;<--- '0'
end if
else ;<--- error: unexpected instruction.
end if
This can be fixed by the addition of four instruction to do a top-down memory copy. In ASSEMBLE.INC around line 980:
remove_structure_data:
push esi edi
mov esi,[structures_buffer]
mov ecx,ebx
sub ecx,esi
lea edi,[esi+20h]
mov [structures_buffer],edi
shr ecx,2
lea esi,[esi+ecx*4-4] ;<--- add
lea edi,[edi+ecx*4-4] ;<--- add
std ;<--- add
rep movs dword [edi],[esi]
cld ;<--- add
pop edi esi
ret