EAccessViolation at RecompileInContext if value is add in array

Issue #178 open
Tino-T created an issue

Hi,

the following test case causes the following errors:

  1. Im Projekt LanguageTests.exe ist eine Exception der Klasse EAccessViolation mit der Meldung 'Zugriffsverletzung bei Adresse 00701707 in Modul 'LanguageTests.exe'. Lesen von Adresse 00000000' aufgetreten.

2. Im Projekt LanguageTests.exe ist eine Exception der Klasse EAssertionFailed mit der Meldung 'Assertion fehlgeschlagen (C:\xxx\Source\dwsStack.pas, Zeile 521)' aufgetreten.

3. Im Projekt LanguageTests.exe ist eine Exception der Klasse EScriptError mit der Meldung 'Assertion fehlgeschlagen (C:\xxx\Source\dwsStack.pas, Zeile 521)' aufgetreten.

Test-Case:

procedure TCornerCasesTests.RecompileInContextVarArray;
var
   prog : IdwsProgram;
   exec : IdwsProgramExecution;

   procedure Run(Line, Check: string);
   begin
      FCompiler.RecompileInContext(prog, Line);
      exec.RunProgram(0);
      CheckEquals(Check, exec.Result.ToString, 're compile line: "' + Line + '"');
   end;

begin
   prog:=FCompiler.Compile('Print("Recompile Array of Integer"); ');

   exec:=prog.BeginNewExecution;
   try
      Run('var i : array of integer;', '');
      Run('i.add(78);', '');
      Run('Print(i[0]);', '78');
   finally
      exec.EndProgram;
   end;
end;

When executing the line

Run('i.add(78);', '');

the errors are output.

Comments (2)

  1. Eric Grange repo owner

    The issue appears to be that the variable initialization is added to the program’s InitExpr, which is executed in BeginProgram (BeginNewExecution), and not executed any further. When recompiling in context with a running instance, the initialization would need to be duplicated, once in InitExpr (for future executions, and in case of future RecompileInContext) and once in the current recompiled program expr

  2. Log in to comment