فهرست منبع

compiler: specialize record methods the same way as currently done for object and class methods + test

git-svn-id: trunk@16726 -
paul 14 سال پیش
والد
کامیت
f5965a9ce4
3فایلهای تغییر یافته به همراه27 افزوده شده و 5 حذف شده
  1. 1 0
      .gitattributes
  2. 5 5
      compiler/psub.pas
  3. 21 0
      tests/test/tgeneric34.pp

+ 1 - 0
.gitattributes

@@ -9427,6 +9427,7 @@ tests/test/tgeneric30.pp svneol=native#text/pascal
 tests/test/tgeneric31.pp svneol=native#text/pascal
 tests/test/tgeneric32.pp svneol=native#text/pascal
 tests/test/tgeneric33.pp svneol=native#text/pascal
+tests/test/tgeneric34.pp svneol=native#text/pascal
 tests/test/tgeneric4.pp svneol=native#text/plain
 tests/test/tgeneric5.pp svneol=native#text/plain
 tests/test/tgeneric6.pp svneol=native#text/plain

+ 5 - 5
compiler/psub.pas

@@ -1984,20 +1984,20 @@ implementation
         oldsymtablestack   : tsymtablestack;
         pu : tused_unit;
         hmodule : tmodule;
-        specobj : tobjectdef;
+        specobj : tabstractrecorddef;
       begin
         if not((tsym(p).typ=typesym) and
                (ttypesym(p).typedef.typesym=tsym(p)) and
-               (ttypesym(p).typedef.typ=objectdef) and
+               (ttypesym(p).typedef.typ in [objectdef,recorddef]) and
                (df_specialization in ttypesym(p).typedef.defoptions)
               ) then
           exit;
 
         { Setup symtablestack a definition time }
-        specobj:=tobjectdef(ttypesym(p).typedef);
+        specobj:=tabstractrecorddef(ttypesym(p).typedef);
         oldsymtablestack:=symtablestack;
         symtablestack:=tsymtablestack.create;
-        if not assigned(tobjectdef(ttypesym(p).typedef).genericdef) then
+        if not assigned(specobj.genericdef) then
           internalerror(200705151);
         hmodule:=find_module_from_symtable(specobj.genericdef.owner);
         if hmodule=nil then
@@ -2016,7 +2016,7 @@ implementation
           symtablestack.push(hmodule.localsymtable);
 
         { procedure definitions for classes or objects }
-        if is_class_or_object(specobj) then
+        if is_class_or_object(specobj) or is_record(specobj) then
           begin
             for i:=0 to specobj.symtable.DefList.Count-1 do
               begin

+ 21 - 0
tests/test/tgeneric34.pp

@@ -0,0 +1,21 @@
+program tgeneric34;
+
+{$mode delphi}
+
+type
+  TFoo<T> = record
+    function DoSomething(Arg: T): T;
+  end;
+
+function TFoo<T>.DoSomething(Arg: T): T;
+begin
+  Result := Arg;
+end;
+
+var
+  FooInt: TFoo<Integer>;
+begin
+  if FooInt.DoSomething(1) <> 1 then
+    halt(1);
+end.
+