On 25/08/2026 21:42, Sven Barth via fpc-devel wrote:
Am 25.08.2026 um 09:21 schrieb Martin Frb via fpc-devel:
*** But the question is: Could the compiler just write that class on
the top level? ***
No, it makes no logical sense to put a type, that is *logically* a
child of a routine be part of the top level. Also it may contain
references to types that are local to the surrounding routine.
Ok.
btw, and unrelated to my initial reasons... But has this been tested
with gdb/lldb?
I don't know if it is related to this or maybe it could be something
entirely else, but my gdb (17.1 on Windows) reports (when trying to step
through an anon proc / pascal code at the end)
=> line 22 is outside / calling the invoke.
=> line 14 is correct
=> and then gdb looses it.
Thread 1 hit Breakpoint 1, B (X=0x14e7cf8) at project1.lpr:22
22 write(x());
(gdb) s
WRPR_$P$PROJECT1$_$F$$TFUNC_$$_$CAPTURERCLASS_1_1_10_10_$_P$PROJECT1$_$F$$TFUNC_$$HK1jjfl_kbwP
() at project1.lpr:14
14 result := function: integer begin
(gdb) n
0x0000000100001709 in INVOKE__FPCINTERNAL__1_1_14_21 (this=0x14e7cf8)
(gdb) n
Single stepping until exit from function INVOKE__FPCINTERNAL__1_1_14_21,
which has no line number information.
2B (X=0x14e7cf8) at project1.lpr:21
21 begin
(gdb) n
23 end;
The line info is there. So that must be some issue in the GDB that I
have. (interestingly gdb also reports the addresses for those lines to
the IDE on a different query)
I haven't tested with LLDB.
FpDebug had no problems.
program Project1;
{$Mode objfpc}
{$ModeSwitch anonymousfunctions}
{$ModeSwitch functionreferences}
type TFunc = reference to function: integer;
var
n: TFunc;
function f: TFunc;
var a: integer;
begin
a := 1;
result := function: integer begin
inc(a);
result := a;
end;
end;
procedure b(x: TFunc);
begin
write(x());
end;
begin
n := f;
b(n);
b(n);
b(n);
end.
_______________________________________________
fpc-devel maillist - [email protected]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel