bug when using generics with the generic parameter as descendant
Original Reporter info from Mantis: soerensen3
-
Reporter name:
Original Reporter info from Mantis: soerensen3
- Reporter name:
Description:
Consider this working code to declare a generic.
gNamedObject < CParent: class > = class ( CParent )
private
FName: String;
published
property Name: String read FName write FName;
end;
If specialized it can add the name property to any class.
TNamedPersistent = gNamedObject < TPersistent >;
However if I try to override the destructor in a generic like this it gives me an error even without specializing.
gObjectWithChildren < CParent: TObject > = class ( CParent )
private
type TCustomList = TFPGObjectList<CParent>;
var FChildren: TCustomList; //Should be initialized in constructor and destroyed in destructor
public
constructor Create;
destructor Destroy; override; //<- Error: There is no method in an ancestor class to be overridden: "destructor Destroy;"
property Children: TCustomList read FChildren write FChildren;
end;
Since every class is derived from TObject which defines a virtual destructor this should not happen. Even if a make a constraint for CParent to be TObject it is still the same (.. < CParent: TObject > ..).
Please see attachment for the full code.
Steps to reproduce:
Compile the attached code once as is and the second with the define in the beginning enabled.
- Compiles
- gives this error: Project1.pas(36,19) Error: There is no method in an ancestor class to be overridden: "destructor Destroy;"
Additional information:
This happens on both pascal mode and delphi mode.
Mantis conversion info:
- Mantis ID: 32054
- OS: any
- OS Build: any
- Platform: any
- Version: 3.0.2