View Issue Details

IDProjectCategoryView StatusLast Update
0031568FPCDocumentationpublic2018-04-17 01:28
ReporterAfrican Wild DogAssigned ToMichael Van Canneyt 
PrioritynormalSeverityfeatureReproducibilityalways
Status closedResolutionfixed 
Product VersionProduct Build 
Target Version3.2.0Fixed in Version3.1.1 
Summary0031568: Interface Inheritance Bug
DescriptionThe compiler are not able to recognize interfance inheritance and implementors.

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

"interface_bug.pas(41,44) Error: Incompatible types: got "TImplementor" expected "IParentInterface""
Steps To ReproduceCompile the unit bellow:


== CODE ====

unit interface_bug;

{$mode objfpc}

interface

type

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

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

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

implementation

procedure TImplementor.Foo;
begin

end;

procedure TImplementor.Bar;
begin

end;

initialization
  ParentImplementorInstance := TImplementor.Create;

end.

===
TagsNo tags attached.
Fixed in Revision1457
FPCOldBugId
FPCTarget
Attached Files

Activities

African Wild Dog

2017-03-19 20:16

reporter   ~0099071

There is a workaround: cast to parent interface

...

ParentImplementorInstance := TImplementor.Create as IParentInterface;

..

Martok

2017-03-19 23:31

reporter   ~0099073

You need to list all inherited interfaces in the parent list for the auto-cast to work.

In this case:
  TImplementor = class(TInterfacedObject, IChildInterface, IParentInterface)

This is the same behaviour as Delphi, by the way.

Thaddy de Koning

2017-03-20 09:32

reporter   ~0099076

Yes, it is not a work-around: with interfaces this is the correct way.
Look at the GUIDs

African Wild Dog

2017-03-31 19:12

reporter   ~0099308

Although it's the same behavior as Delphi, it's a bug IMHO. Because, TImplementor, when implementing the child interface, it necessarily implements the parent interface.

In other words, if TImplementor implements the parent interface, why can not I assign a IParentInterface variable to TImplementor?

Marco van de Voort

2017-04-01 18:14

manager   ~0099333

Last edited: 2017-04-01 18:15

View 2 revisions

Having them separate allows to delegate them to different classes. But if that is the reason?

Still, this is compatible.

African Wild Dog

2017-04-07 17:40

reporter   ~0099475

The problem is that the compiler is saying that an IParentInterface variable is not assignment compatible with a class that implements IChildInterface. It is a semantic problem.

By analogy, it is as if i have "A: TObject" variable and "A" not being assignment compatible whith any of the TObject descendant classes.

Marco van de Voort

2017-05-22 16:13

manager   ~0100604

That's what you would like, but not how the language works. You need to list all interface dependencies in the class declaration. This is documented in Delphi, and if it is not in FPC, that is documentation bug.

If you want to change the language, please use the fpc-devel maillist.

African Wild Dog

2017-11-08 14:29

reporter   ~0103959

"That's what you would like, but not how the language works."
Correct. Confirmed this behavior in Delphi too.
I don't wanna to request a change in the language before Delphi changes too.
Thanks for the feedback.

Michael Van Canneyt

2018-01-13 17:40

administrator   ~0105744

I documented it in the Interfaces chapter, with explicit examples.

Issue History

Date Modified Username Field Change
2017-03-19 20:15 African Wild Dog New Issue
2017-03-19 20:16 African Wild Dog Note Added: 0099071
2017-03-19 23:31 Martok Note Added: 0099073
2017-03-20 09:32 Thaddy de Koning Note Added: 0099076
2017-03-31 19:12 African Wild Dog Note Added: 0099308
2017-03-31 19:40 Marco van de Voort Severity minor => feature
2017-04-01 18:14 Marco van de Voort Note Added: 0099333
2017-04-01 18:15 Marco van de Voort Note Edited: 0099333 View Revisions
2017-04-07 17:40 African Wild Dog Note Added: 0099475
2017-05-22 16:13 Marco van de Voort Note Added: 0100604
2017-05-22 19:23 Marco van de Voort Assigned To => Marco van de Voort
2017-05-22 19:23 Marco van de Voort Status new => feedback
2017-05-23 14:28 Marco van de Voort Assigned To Marco van de Voort =>
2017-11-08 14:29 African Wild Dog Note Added: 0103959
2017-11-08 14:29 African Wild Dog Status feedback => new
2018-01-05 21:05 Jonas Maebe Category Compiler => Documentation
2018-01-05 21:05 Jonas Maebe Assigned To => Michael Van Canneyt
2018-01-05 21:05 Jonas Maebe Status new => assigned
2018-01-13 17:40 Michael Van Canneyt Fixed in Revision => 1457
2018-01-13 17:40 Michael Van Canneyt Note Added: 0105744
2018-01-13 17:40 Michael Van Canneyt Status assigned => resolved
2018-01-13 17:40 Michael Van Canneyt Fixed in Version => 3.1.1
2018-01-13 17:40 Michael Van Canneyt Resolution open => fixed
2018-01-13 17:40 Michael Van Canneyt Target Version => 3.2.0
2018-04-17 01:28 African Wild Dog Status resolved => closed