[fpc-devel] Question on interface inheritance...

Martin Frb lazarus at mfriebe.de
Sun Feb 1 15:29:20 CET 2026


The below example throws a compile error... Technical correct, well...
(doesn't matter which of the 2 intf I use as return type...)

Also, same when doing (in the 2 interfaces / yes override compiles with 
inherited return type)
     function GetFoo: TIntfFooBase; virtual;
     function GetFoo: TIntfFoo; override;

TIntFoo covers all that is TintFooBase => so that should/could cover the 
requirement?

Is that error by indent (for which reason)?
Or by oversight?


In any case, how can it actually be added?
- Obviously I can not have 2 identical functions with just a different 
return type.
- I could do:
     function BaseGetFoo: TIntfFooBase;
     function TIntfBarBase.GetFoo = BaseGetFoo;

But that only compiles if I do add both interfaces:
    TMyClass = class(TObject, TIntfBar, TIntfBarBase)
And then I still get the error about the missing method.


Neither does this work.
     function GetFoo: TIntfFoo;
     function BaseGetFoo: TIntfFooBase;
     function TIntfBar.GetFoo = BaseGetFoo;
Which then gives (the reintroduced method is now missing / of course, 
since the other is forced)
project1.lpr(24,14) Error: No matching implementation for interface 
method "GetFoo:TIntfFoo;" found

and neither (same error / no error about setting the intf method twice)
   TMyClass = class(TObject, TIntfBar)
     function NewGetFoo: TIntfFoo;
     function BaseGetFoo: TIntfFooBase;
     function TIntfBar.GetFoo = NewGetFoo;
     function TIntfBar.GetFoo = BaseGetFoo;
   end;



program Project1;
{$Mode objfpc}{$Interfaces CORBA}
type

   TIntfFooBase = interface
   end;
   TIntfFoo = interface(TIntfFooBase)
   end;

   TIntfBarBase = interface
     function GetFoo: TIntfFooBase;
   end;
   TIntfBar = interface(TIntfBarBase)
     function GetFoo: TIntfFoo; reintroduce;
   end;

   // project1.lpr(21,14) Error: No matching implementation for 
interface method "GetFoo:TIntfFooBase;" found
   TMyClass = class(TObject, TIntfBar)
     function GetFoo: TIntfFoo;
   end;

function TMyClass.GetFoo: TIntfFoo;
begin
   //
end;

begin
end.



More information about the fpc-devel mailing list