[fpc-devel] Generic method works on Linux, not on Windows?

Yuriy Sydorov jura at cp-lab.com
Tue May 26 23:36:49 CEST 2020


On 26.05.2020 22:41, Joost van der Sluis wrote:
> I have something strange.
> 
> I have a generic function defined as follows:
> 
> generic function TJSONRttiStreamClass.CreateObjectFromJSONString<T (AJSONString: TJSONStringType; ADescriptionTag: 
> string = ''): T;
> begin
>    Result := nil;
> end;
> 
> When I call it, like this:
> 
> LaunchRequest := FSerializer.specialize CreateObjectFromJSONString<TDabLaunchRequest>(ACommandText);
> 
> Then I get a compiler-error on Windows, while it works on Linux:
> 
> csjsonrttistreamhelper.pas(81,1) Error: Wrong number of parameters specified for call to "$fin$00000037"
> 
> When I make the function empty (Remove Result := nil) it compiles.
> 
> Any idea what to look for?

Does it happen with the fpc trunk?
If yes, what revision do you use? It looks like an issue with my initial implementation of the $parentfp parameter 
optimization. "$fin$00000037" is a reference to an internal SEH handler procedure which is a special nested procedure.

The latest trunk for win32 compiles fine the following modified example:

{$mode objfpc}{$H+}

generic function CreateObjectFromJSONString<T>(AJSONString: string; ADescriptionTag: string = ''): T;
begin
   Result := nil;
end;

var
   LaunchRequest: TObject;
begin
   LaunchRequest := specialize CreateObjectFromJSONString<TObject>('qwe');
end.

Yuriy.


More information about the fpc-devel mailing list