Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2017-03

Interface Inheritance Bug

6 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

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*.

===========

Sven Barth
to African Wild Dog
"African Wild Dog" wrote 6 lines
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

African Wild Dog
to Sven Barth

2017-03-19 5:25 GMT-03:00 Sven Barth via fpc-pascal <

Show quoted text 8 lines
: 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;

..

Sven Barth
to African Wild Dog
"African Wild Dog" wrote 5 lines
2017-03-19 5:25 GMT-03:00 Sven Barth via fpc-pascal < : > > 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 ;) ).

Show quoted text 7 lines
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

African Wild Dog
to Sven Barth

2017-03-19 15:20 GMT-03:00 Sven Barth via fpc-pascal <

Show quoted text 8 lines
: But without the cast you get the same error, yes? Regards, Sven

Yes, i need to cast.

Regards

African Wild Dog
to Sven Barth: generics. "TImplementor<System.LongInt>" expected "IParentInterface<System.LongInt>"" I…

2017-03-19 5:25 GMT-03:00 Sven Barth via fpc-pascal <

Show quoted text 23 lines
: Am 19.03.2017 05:07 schrieb "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>"" 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.
Issued as http://bugs.freepascal.org/view.php?id=31568. <http://bugs.freepascal.org/view.php?id=31568>

Regards