Skip to content

Cannot override method in generic class

System Information

  • Operating system: Windows
  • Processor architecture: x86-64
  • Compiler version: trunk (bf2a3566)
  • Device: Computer

Steps to reproduce

We get error

unit2.pas(16,15) Error: There is no method in an ancestor class to be overridden: "GetTypeTagFromRow(TObject):System.LongInt;"

To reproduce we need 3 files

First one

unit Unit2;

{$mode Delphi}

interface

type

  { TGsAbstractObjectList }

  TGsAbstractObjectList<T: TObject> = class
  protected
    function  GetTypeTagFromRow(ARow: TObject): Integer; virtual;
  end;

implementation

{ TGsAbstractObjectList<T> }

function TGsAbstractObjectList<T>.GetTypeTagFromRow(ARow: TObject): Integer;
begin
  Result := 0;
end;

end.

second one:

unit Unit1;

{$mode Delphi}

interface

uses
  Unit2;

type

  { TCatCatalog }

  TCatCatalog<TItem: TObject> = class(TGsAbstractObjectList<TGsAbstractObjectList<TItem>>)
  protected
    function  GetTypeTagFromRow(ARow: TObject): Integer; override; ///!!!!!!!!!!!!!!! BUG IS HERE !!!!!!!!!!!!!!!!!!!!!!!
  end;

implementation

{ TCatCatalog }

function TCatCatalog<TItem>.GetTypeTagFromRow(ARow: TObject): Integer;
begin
  Result := 1;
end;

end.

and third one (project)

program project1;
{$mode delphi}

uses unit2, unit1;

type
  TSmetaUnitsCatalog = class(TCatCatalog<TObject>)

  end;


begin
  TSmetaUnitsCatalog.Create;
end.

Possible fixes

As I can see issue is in is_visible_for_object.owner_hierarchy_related. This function doesnot work correctly in case when compiler is checking is TCatCatalog inherited from TGsAbstractObjectList (returns false, but should return true)

Edited by Евгений Савин
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information