Internal Error 2022011101 with nested anonymous functions
Summary
Nested anonymous functions don't work (raise IE 2022011101), iff the outer anonymous function captured a local variable.
Putting the inner anonymous function in a function variable and passing that in from the outer context works fine.
System Information
- Operating system: Windows
- Processor architecture: x86, x86-64
- Compiler version: fpc-3.3.1-9c72ab (2022-08-07)
Steps to reproduce
Attempt to compile this project:
Example Project
program Project1;
{$mode objfpc}{$H+}
{$ModeSwitch anonymousfunctions}
{$ModeSwitch functionreferences}
type
TProc = reference to procedure;
procedure Meth1(proc: TProc);
begin
Writeln('Enter Meth1');
proc();
Writeln('Exit Meth1');
end;
procedure Meth2(proc: TProc);
begin
Writeln('Enter Meth2');
proc();
Writeln('Exit Meth2');
end;
procedure Test;
var
z: integer;
begin
Meth1(procedure begin
Writeln('Enter Anon1');
z:= 42; // this captured assigment causes the problem
Meth2(procedure begin
Writeln('Anon2');
end);
Writeln('Exit Anon1');
end);
end;
begin
Test;
end.
What is the current bug behavior?
Internal Error 2022011101
What is the expected (correct) behavior?
Should compile and give output like:
Enter Meth1
Enter Anon1
Enter Meth2
Anon2
Exit Meth2
Exit Anon1
Exit Meth1
Edited by Sebastian Hütter