* allow usage of nested types

git-svn-id: trunk@5165 -
This commit is contained in:
florian 2006-11-01 23:33:55 +00:00
parent fa32d2c240
commit 0c1b7910ab
3 changed files with 77 additions and 1 deletions

1
.gitattributes vendored
View File

@ -6361,6 +6361,7 @@ tests/test/tgeneric4.pp svneol=native#text/plain
tests/test/tgeneric5.pp svneol=native#text/plain
tests/test/tgeneric6.pp svneol=native#text/plain
tests/test/tgeneric7.pp svneol=native#text/plain
tests/test/tgeneric8.pp svneol=native#text/plain
tests/test/tgoto.pp svneol=native#text/plain
tests/test/theap.pp svneol=native#text/plain
tests/test/thintdir.pp svneol=native#text/plain

View File

@ -1260,7 +1260,7 @@ implementation
if assigned(p1) then
begin
if not assigned(p1.resultdef) then
do_typecheckpass(p1);
do_typecheckpass(p1);
isclassref:=(p1.resultdef.deftype=classrefdef);
end
else
@ -1308,6 +1308,10 @@ implementation
Message(parser_e_only_class_methods_via_class_ref);
handle_propertysym(tpropertysym(sym),sym.owner,p1);
end;
typesym:
begin
p1:=ctypenode.create(ttypesym(sym).typedef);
end;
else internalerror(16);
end;
end;

71
tests/test/tgeneric8.pp Normal file
View File

@ -0,0 +1,71 @@
{$mode objfpc}
type
generic TList<_T>=class(TObject)
type
PListItem = ^TListItem;
TListItem = record
data : _T;
next : PListItem;
end;
TIterator = PListItem;
var
first : PListItem;
function GetFirst : TIterator; inline;
function GetNext(i : TIterator) : TIterator; inline;
procedure Add(item: _T);
end;
procedure TList.Add(item: _T);
var
newitem : PListItem;
begin
new(newitem);
newitem^.data:=item;
newitem^.next:=first;
first:=newitem;
end;
function TList.GetFirst : TIterator; inline;
begin
result:=first;
end;
function TList.GetNext(i : TIterator) : TIterator; inline;
begin
result:=i^.next;
end;
type
TMyIntList = specialize TList<integer>;
TMyStringList = specialize TList<string>;
var
ilist : TMyIntList;
slist : TMyStringList;
someInt : integer;
iterator : TMyIntList.TIterator;
begin
someInt:=10;
ilist := TMyIntList.Create;
ilist.Add(someInt);
ilist.Add(someInt+1);
iterator:=ilist.GetFirst;
writeln(iterator^.data);
if iterator^.data<>11 then
halt(1);
iterator:=ilist.GetNext(iterator);
writeln(iterator^.data);
if iterator^.data<>10 then
halt(1);
slist := TMyStringList.Create;
slist.Add('Test1');
slist.Add('Test2');
writeln(slist.first^.data);
if slist.first^.data<>'Test2' then
halt(1);
writeln('ok');
end.