[fpc-pascal] Traits Proposal

Ryan Joseph genericptr at gmail.com
Mon Feb 15 16:52:20 CET 2021



> On Feb 14, 2021, at 11:43 PM, Sven Barth via fpc-pascal <fpc-pascal at lists.freepascal.org> wrote:
> 
> Same names should be rejected. Providing a new implementation can be controlled using the interface alias:
> 
> === code begin ===
> 
> type
>   TMyClass = class(TInterfacedObject, IMyIntf)
>   private
>     fMyRecord: TMyRecord;
>   public
>     procedure IMyIntf.Test2 = MyTest2;
>     // this will hoist all methods except Test2 from TMyRecord and MyTest2 as Test2 from the class itself
>     property MyRecord: TMyRecord read fMyRecord implements IMyIntf; default;
>     propcedure MyTest2;
>   end;

So "procedure IMyIntf.Test2 = MyTest2;" basically tells the compiler to ignore the duplicate name resections and then when it encounters the MyTest2 there is no error?

A duplicate name in this context is basically just method hiding (like in normal OOP) so you could argue it should be allowed. If the property came before then the interface would hide the local declaration. Not too different from how normal inheritance works really.

Regards,
	Ryan Joseph



More information about the fpc-pascal mailing list