Prechádzať zdrojové kódy

* correctly handle the genericdef being a procdef, otherwise no code will be generated (and no error either :/ )
+ added test

git-svn-id: trunk@43586 -

svenbarth 5 rokov pred
rodič
commit
ef6c9e930b
3 zmenil súbory, kde vykonal 55 pridanie a 3 odobranie
  1. 1 0
      .gitattributes
  2. 21 3
      compiler/pgenutil.pas
  3. 33 0
      tests/tbs/tb0665.pp

+ 1 - 0
.gitattributes

@@ -12976,6 +12976,7 @@ tests/tbs/tb0661.pp svneol=native#text/plain
 tests/tbs/tb0662.pp svneol=native#text/pascal
 tests/tbs/tb0663.pp svneol=native#text/plain
 tests/tbs/tb0664.pp svneol=native#text/pascal
+tests/tbs/tb0665.pp svneol=native#text/pascal
 tests/tbs/ub0060.pp svneol=native#text/plain
 tests/tbs/ub0069.pp svneol=native#text/plain
 tests/tbs/ub0119.pp svneol=native#text/plain

+ 21 - 3
compiler/pgenutil.pas

@@ -472,8 +472,21 @@ uses
         errorrecovery:=false;
         if (symname='') and
             (not assigned(genericdef) or
-            not assigned(genericdef.typesym) or
-            (genericdef.typesym.typ<>typesym)) then
+              (
+                (genericdef.typ<>procdef) and
+                (
+                  not assigned(genericdef.typesym) or
+                  (genericdef.typesym.typ<>typesym)
+                )
+              ) or
+              (
+                (genericdef.typ=procdef) and
+                (
+                  not assigned(tprocdef(genericdef).procsym) or
+                  (tprocdef(genericdef).procsym.typ<>procsym)
+                )
+              )
+            ) then
           begin
             errorrecovery:=true;
             result:=generrordef;
@@ -592,7 +605,12 @@ uses
         { use the name of the symbol as procvars return a user friendly version
           of the name }
         if symname='' then
-          genname:=ttypesym(genericdef.typesym).realname
+          begin
+            if genericdef.typ=procdef then
+              genname:=tprocdef(genericdef).procsym.realname
+            else
+              genname:=ttypesym(genericdef.typesym).realname;
+          end
         else
           genname:=symname;
 

+ 33 - 0
tests/tbs/tb0665.pp

@@ -0,0 +1,33 @@
+program tb0665;
+
+{$mode objfpc}
+{$modeswitch advancedrecords}
+
+type
+  TTest = record
+    b: Boolean;
+    function Test(aArg: Pointer): Boolean; inline;
+    generic function Test<T>: Boolean; inline;
+  end;
+
+function TTest.Test(aArg: Pointer): Boolean;
+begin
+  b := True;
+  Result := True;
+end;
+
+generic function TTest.Test<T>: Boolean;
+begin
+  Result := Test(Nil);
+end;
+
+var
+  t: TTest;
+begin
+  t.b := False;
+  { check for side effects to ensure that the code was correctly generated }
+  t.specialize Test<LongInt>;
+  if not t.b then
+    Halt(1);
+  Writeln('ok');
+end.