Hairy Pixels via fpc-pascal <fpc-pascal@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 >
_______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal