2
0
Эх сурвалжийг харах

* allow usage of nested types

git-svn-id: trunk@5165 -
florian 19 жил өмнө
parent
commit
0c1b7910ab

+ 1 - 0
.gitattributes

@@ -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

+ 5 - 1
compiler/pexpr.pas

@@ -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 - 0
tests/test/tgeneric8.pp

@@ -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.