{$MODE OBJFPC} { -*- text -*- } program tests; type generic TFoo = class end; generic TBar = class type TIntegerSpecializedFoo = specialize TFoo; TSelfSpecializedFoo = specialize TFoo; function SelfTest(): TBar; // returns a TBar // TSpecializedBar = specialize TBar; // this rightly would not compile since TBar here refers to the specialized TBar end; function TBar.SelfTest(): TBar; begin Result := Self; end; begin end.