Interface Inheritance Bug

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Interface Inheritance Bug

African Wild Dog
Hello,

Test env: debian jessie amd64 - fpc 3.0.2

It seems free pascal have a bug when handling interface inheritance using generics.

When i try to compile the unit bellow, i get this error:

"interface_bug.pas(41,44) Error: Incompatible types: got "TImplementor<System.LongInt>" expected "IParentInterface<System.LongInt>""


=== CODE ===

unit interface_bug;

{$mode delphi}

interface

type

  IParentInterface<T> = interface           
    ['{0F78D56E-85A6-4024-98D7-720D7C7B9573}']
    procedure Foo;
  end;

  IChildInterface<T> = interface(IParentInterface<T>)
    ['{1AB2EB85-6843-462E-8CE4-32ECC065011E}']
    procedure Bar;
  end;

  TImplementor<T> =  class(TInterfacedObject, IChildInterface<T>)
  public
    procedure Foo;
    procedure Bar;
  end;
 
var
  ParentImplementorInstance: IParentInterface<Integer>;

implementation

procedure TImplementor<T>.Foo;
begin

end;

procedure TImplementor<T>.Bar;
begin

end;

initialization
  ParentImplementorInstance:=TImplementor<Integer>.Create;

end.



===========



_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Interface Inheritance Bug

Free Pascal - General mailing list

Am 19.03.2017 05:07 schrieb "African Wild Dog" <[hidden email]>:
>
> Hello,
>
> Test env: debian jessie amd64 - fpc 3.0.2
>
> It seems free pascal have a bug when handling interface inheritance using generics.
>
> When i try to compile the unit bellow, i get this error:
>
> "interface_bug.pas(41,44) Error: Incompatible types: got "TImplementor<System.LongInt>" expected "IParentInterface<System.LongInt>""

I think this will happen with non-generic interfaces as well. So please test with those and if possible also with 3.1.1 and report a bug if necessary (preferable with a non-generic example, makes things easier to debug ;) ).

Regards,
Sven


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Interface Inheritance Bug

African Wild Dog
2017-03-19 5:25 GMT-03:00 Sven Barth via fpc-pascal <[hidden email]>:

I think this will happen with non-generic interfaces as well. So please test with those and if possible also with 3.1.1 and report a bug if necessary (preferable with a non-generic example, makes things easier to debug ;) ).


With non-generic types there is a workaround: cast to parent interface:

...

ParentImplementorInstance := TImplementor.Create as
IParentInterface;

..




_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Interface Inheritance Bug

Free Pascal - General mailing list

Am 19.03.2017 17:55 schrieb "African Wild Dog" <[hidden email]>:
>
> 2017-03-19 5:25 GMT-03:00 Sven Barth via fpc-pascal <[hidden email]>:
>>
>> I think this will happen with non-generic interfaces as well. So please test with those and if possible also with 3.1.1 and report a bug if necessary (preferable with a non-generic example, makes things easier to debug ;) ).
>
>
> With non-generic types there is a workaround: cast to parent interface:
>
> ...
>
> ParentImplementorInstance := TImplementor.Create as IParentInterface;

But without the cast you get the same error, yes?

Regards,
Sven


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Interface Inheritance Bug

African Wild Dog
2017-03-19 15:20 GMT-03:00 Sven Barth via fpc-pascal <[hidden email]>:

But without the cast you get the same error, yes?

Regards,
Sven



Yes, i need to cast.

Regards

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Interface Inheritance Bug

African Wild Dog
In reply to this post by Free Pascal - General mailing list
2017-03-19 5:25 GMT-03:00 Sven Barth via fpc-pascal <[hidden email]>:

Am 19.03.2017 05:07 schrieb "African Wild Dog" <[hidden email]>:
>
> Hello,
>
> Test env: debian jessie amd64 - fpc 3.0.2
>
> It seems free pascal have a bug when handling interface inheritance using generics.
>
> When i try to compile the unit bellow, i get this error:
>
> "interface_bug.pas(41,44) Error: Incompatible types: got "TImplementor<System.LongInt>" expected "IParentInterface<System.LongInt>""

I think this will happen with non-generic interfaces as well. So please test with those and if possible also with 3.1.1 and report a bug if necessary (preferable with a non-generic example, makes things easier to debug ;) ).


Bug confirmed on 3.1.1.
Regards

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Loading...