[fpc-pascal] Arguments gets corrupted with anonymous nested function
Sven Barth
pascaldragon at googlemail.com
Sun Sep 4 21:36:59 CEST 2022
Hairy Pixels via fpc-pascal <fpc-pascal at lists.freepascal.org> schrieb am
So., 4. Sep. 2022, 18:07:
> The following program uses an anonymous nested function which captures a
> local variable. It seems the arguments get corrupted (likely because of the
> hidden first param for the nested function signature) and prints garbled
> data. I reduced this snippet down from another project but I’m not sure if
> this is the best way to reproduce the real issue.
>
> Is this a compiler bug or am I doing something wrong?
>
> ===========================
>
> {$mode objfpc}
> {$modeswitch anonymousfunctions}
> {$modeswitch nestedprocvars}
>
> program test;
>
> type
> generic TMyClass<T> = class
> type
> TCallback = procedure (data: T) is nested;
>
> procedure Call(callback: TCallback);
> procedure Test;
> end;
>
> procedure TMyClass.Call(callback: TCallback);
> begin
> callback(default(T));
> end;
>
> procedure TMyClass.Test;
> var
> i: integer;
> begin
> Call(procedure(data: T)
> begin
> Inc(i);
> writeln(data); // prints garbled data like 73251232
> end);
> end;
>
> begin
> specialize TMyClass<Integer>.Create.Test;
> end.
>
Does this also happen if you don't use a class? Otherwise it might be
related with the other error you already reported. But report this anyway,
I'll simply mark it as duplicate if necessary...
Regards,
Sven
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20220904/bdec6252/attachment.htm>
More information about the fpc-pascal
mailing list