[fpc-devel] generic and type compatibility / interface vs class ...
Martin Frb
lazarus at mfriebe.de
Tue Feb 3 17:05:21 CET 2026
On 03/02/2026 16:58, Hairy Pixels via fpc-devel wrote:
> On Feb 3, 2026 at 10:42:05 PM, Martin Frb via fpc-devel
> <fpc-devel at lists.freepascal.org> wrote:
>> https://gitlab.com/freepascal.org/fpc/source/-/issues/41604
>
> program Project1;
> {$Mode objfpc}
> {$Interfaces CORBA}
> type
> IFoo = interface end;
> TBar = class(TObject, IFoo) end;
>
> generic MyGen<A: IFoo> = class end;
>
> TSome = specialize MyGen<TBar>;
>
> begin
>
> end.
> ok so I can see the whole thing now and this should compile. TBar
> implements IFoo and "A" must conform to IFoo so TBar is compatible
> with "A".
>
Not really.
Below stops compiling, when you uncomment the specialize.
IFoo has a method Test.
TBar does not have that. Only TBar as IFoo would have it. But it isn't
cast to IFoo.
program Project1;
{$Mode objfpc}
{$Interfaces CORBA}
type
IFoo = interface
procedure Test;
end;
TBar = class(TObject, IFoo)
procedure BarTest; virtual; abstract;
procedure IFoo.Test = BarTest;
end;
generic MyGen<A: IFoo> = class
procedure p1(x: A);
end;
//TSome = specialize MyGen<TBar>;
procedure MyGen.p1(x: A);
begin
x.Test
end;
begin
end.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20260203/bf1f7a28/attachment.htm>
More information about the fpc-devel
mailing list