On 25/07/2025 15:20, Mattias Gaertner via fpc-devel wrote:


On 7/25/25 13:44, Martin Frb via fpc-devel wrote:
Currently you can't do

type
   generic TFoo<A> = class
      procedure Bar; virtual;
   end;

   generic FooChild<F: TFoo> = class(F)
      procedure Bar; override;
   end;

Can you use:

   generic FooChild<T> = class(specialize TFoo<T>)
      procedure Bar; override;
   end;
?

No.

One example is that I have several
  TItem1, TItem2, TItem3,...
and for each a
    TItem1List = specialize TFpgList<TItem1>;

But I don't actually use TItem1, ....

I use
  TMyFinalItem1 =
       specialize TFeatureX<
           specialize TFeatureY<
               specialize TFeatureZ< TItem1 >
          >
      >;

And each list needs to be
  TMyFinalItem1 =
       specialize TFeatureXForList<
           specialize TFeatureYForList<
               specialize TFeatureZForList< specialize TFpgList<TItem1>   >
          >
      >;


Currently I can swap the order, and git it working by creating a non generic base.... But that introduces dependencies that were not wanted...


Also, the error by the compiler is
     Error: Generics without specialization cannot be used as a type for a variable

But
   generic FooChild<F: TFoo> = class(F)

- F is not a variable
- TFoo in not a type (for somethnig), TFoo is a constraint

If that syntax was allowed, it should mean that
-  F must be of any type that is (a descendand of) a specialization of TFoo.

So this is NOT to allow FooChild to be specialized with another generic, but with a (any) specialization of that generic.

_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to