Nested class can't refer to parent generic class name ("Generics without specialization cannot be used as a type...")
Original Reporter info from Mantis: Hixie
-
Reporter name: Ian Hickson
Original Reporter info from Mantis: Hixie
- Reporter name: Ian Hickson
Description:
A generic class can refer to itself by name; the name is substituted by the full name when the generic is specialized. However, this does not extend to nested classes, which makes making enumerators for generics rather awkward.
Steps to reproduce:
type
generic THashTable <TKey, TValue> = class
type
THashTableEnumerator = class
private
FOwner: THashTable; // <-- fails here
function GetCurrent(): TValue;
public
constructor Create(Owner: THashTable); // <-- fails here
function MoveNext(): Boolean;
property Current: TValue read GetCurrent;
end;
function GetEnumerator(): THashTableEnumerator;
var
Foo: THashTable; // <-- this works
procedure Bar(Arg: THashTable); // <-- this works
end;
Additional information:
Compilable test case: http://junkyard.damowmow.com/463
Results in:
tests.pas(13,46) Error: Generics without specialization cannot be used as a type for a variable
tests.pas(29,69) Error: Generics without specialization cannot be used as a type for a variable
tests.pas(41,46) Error: Incompatible type for arg no. 1: Got "THashTable", expected "&LtPos;erroneous type>"
tests.pas(29,45) Hint: Found declaration: constructor THashTable.THashTableEnumerator.Create(&LtPos;erroneous type>);
tests.pas(10,28) Error: Generics without specialization cannot be used as a type for a variable
tests.pas(13,46) Error: Generics without specialization cannot be used as a type for a variable
tests.pas(41,46) Error: Incompatible type for arg no. 1: Got "THashTableLongInt
AnsiString", expected "&LtPos;erroneous type>"
tests.pas(13,22) Hint: Found declaration: constructor THashTableLongInt
AnsiString.THashTableEnumerator.Create(&LtPos;erroneous type>);
tests.pas(67) Fatal: There were 6 errors compiling module, stopping
Mantis conversion info:
- Mantis ID: 19499
- Build: trunk compiled 2011-06-05
- Fixed in version: 3.0.0
- Fixed in revision: 21361 (#dbc410de)
- Monitored by: » Basil Peace (Basil Peace), » kyan (Constantine Yannakopoulos)