On Tue, 28 Dec 2021 23:11:42 +0100 (CET)
Michael Van Canneyt via fpc-pascal <fpc-pascal@lists.freepascal.org>
wrote:

>[...]
> > Slightly off topic, and my Object Pascal is getting a bit rusty as
> > the years go by. <grin> ;-) In your factory above, is the "as
> > IInterface" part needed.

No.

> Can't the FPC compiler automatically cast
> > the return type based on the function return type, and the fact
> > that the compiler should know that TIntf2Impl type implements
> > TInterfacedObject?  

Yes.

> No, theoretically it probably could, but type inference is not
> implemented in Pascal.

This is not type inference.
It compiles with fpc and pas2js:

Function GetMyOtherInterface(Const aName : string) : IInterface;
begin
  Result:=TIntf2Impl.Create;
end;


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

Reply via email to