<div dir="auto"><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Hairy Pixels via fpc-pascal <<a href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a>> schrieb am So., 4. Sep. 2022, 18:07:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">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.<br>
<br>
Is this a compiler bug or am I doing something wrong?<br>
<br>
===========================<br>
<br>
{$mode objfpc}<br>
{$modeswitch anonymousfunctions}<br>
{$modeswitch nestedprocvars}<br>
<br>
program test;<br>
<br>
type<br>
generic TMyClass<T> = class<br>
type<br>
TCallback = procedure (data: T) is nested;<br>
<br>
procedure Call(callback: TCallback);<br>
procedure Test;<br>
end;<br>
<br>
procedure TMyClass.Call(callback: TCallback);<br>
begin<br>
callback(default(T));<br>
end;<br>
<br>
procedure TMyClass.Test;<br>
var<br>
i: integer;<br>
begin<br>
Call(procedure(data: T)<br>
begin<br>
Inc(i);<br>
writeln(data); // prints garbled data like 73251232<br>
end);<br>
end;<br>
<br>
begin<br>
specialize TMyClass<Integer>.Create.Test;<br>
end.<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">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... </div><div dir="auto"><br></div><div dir="auto">Regards, </div><div dir="auto">Sven </div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
</blockquote></div></div></div>