[fpc-devel] generic constraints...
Martin Frb
lazarus at mfriebe.de
Tue Jul 29 10:03:20 CEST 2025
On 29/07/2025 09:53, Mattias Gaertner via fpc-devel wrote:
>
> On 7/25/25 16:31, Martin Frb via fpc-devel wrote:
>>
>> But
>> generic FooChild<F: TFoo> = class(F)
>>
>> - F is not a variable
>> - TFoo in not a type (for somethnig), TFoo is a constraint
>
> The problem is the ambiguity of TFoo, because Delphi (aka modeswitch)
> distinguishes TFoo, TFoo<> and TFoo<,>:
Ok, yes. If ever a generic parameter can refer to an (non specialized)
generic
generic Foo<G: TGeneric> = class
type TSome = G<F> ;
Then the name of the generic can not be used as "any specialized type of
that generic"
Unless it then needs to be prefixed
generic Foo<G: generic TGeneric> = class
And/or less constrained
generic Foo<G: generic> = class
>
> AFAIK there is currently no "Any" placeholder in constraints. It would
> be something like
> generic FooChild<F: specialized TFoo<>> = ...
>
> Although that looks like something was forgotten. Maybe better:
>
> generic FooChild<F: specialized TFoo<*>> = ...
Would be nice to have.
It also needs the placeholders to be able to distinguish
generic TBar<A>
generic TBar<A,B>
generic FooChild<F: specialize TBar<,>) = ...
generic FooChild<F: TBar<,>) = ...
not sure if it should really say "specialize" (even in objfpc) because
it isn't doing it, it is expecting it to be done elsewhere.
@FPC Team: Worth a feature request?
More information about the fpc-devel
mailing list