Free Pascal 中的通用嵌套 class 函数

Generic nested class function in Free Pascal

我尝试编写以下代码以查看是否可以通过结合对通用 class 函数和嵌套 classes 的支持来模拟 Free Pascal 3 中的通用方法:

{$mode delphi}
type TFoo = class
  public
    type TBar<T> = class
      class function Min(const A, B: T): T;
    end;
end;
class function TFoo.TBar<T>.Min(const A, B: T): T;
begin
  if A < B then
    Result := A
  else
    Result := B;
end;

我尝试了几种语法变体,但无论如何我都无法编译它。在这种形式下,编译器在第 8 行 (method identifier expected, Syntax error, ";" expected but "<" found).

给我一个致命错误

如果可能的话,正确的语法是什么?

fpc 3.0.4 中正确且有效的语法,至少在 objfpc 模式下(模式 delphi 未测试):

{$mode objfpc}
type TFoo = class
  public
    type generic TBar<T> = class
      class function Min(const A, B: T): T;
    end;
end;
class function TFoo.TBar.Min(const A, B: T): T;
begin
  ...
end;