Generic: restricting a specialized type
Original Reporter info from Mantis: silvioprog
-
Reporter name: silvioprog
Original Reporter info from Mantis: silvioprog
- Reporter name: silvioprog
Description:
Hello,
I'm trying to port a Delphi code to FPC, and it has a structure like:
TType = class(TObject) end; TTest&LtPos;T1; T2: TType> = class(TObject) end; TFoo = class(TType) end; TBar = class(TTest&LtPos;string, TFoo>) end;
I.e., T1 accepts any type, but T2 accepts only TType and/or their descendants.
I tried the following code in FPC:
TType = class(TObject) end; generic TTest&LtPos;T1; T2: TType> = class(TObject) end; TFoo = class(TType) end; TBar = class(specialize TTest&LtPos;string, TFoo>) end;
But:
Compile Project, Target: project1.exe: Exit code 1, Errors: 2 Unit1.pas(30,34) Error: class type expected, but got "AnsiString" Unit1.pas(30,47) Error: class type expected, but got "&LtPos;erroneous type>"
If I declare "T2" instead of "T2: TType", it compiles, but using this declaration, a programmer can use accidentally a non descendant type of TType.
Thank you!
Mantis conversion info:
- Mantis ID: 27424
- Fixed in version: 3.0.0
- Fixed in revision: 29685 (#04534d5d)