Преглед изворни кода

* function results can be a generic parameter

git-svn-id: trunk@3585 -
florian пре 19 година
родитељ
комит
e4d2d87bb9
3 измењених фајлова са 35 додато и 0 уклоњено
  1. 1 0
      .gitattributes
  2. 12 0
      compiler/pdecsub.pas
  3. 22 0
      tests/webtbs/tw6624.pp

+ 1 - 0
.gitattributes

@@ -6820,6 +6820,7 @@ tests/webtbs/tw5023.pp svneol=native#text/plain
 tests/webtbs/tw5036.pp svneol=native#text/plain
 tests/webtbs/tw5082.pp -text svneol=unset#text/plain
 tests/webtbs/tw6491.pp svneol=native#text/plain
+tests/webtbs/tw6624.pp svneol=native#text/plain
 tests/webtbs/tw6684.pp svneol=native#text/plain
 tests/webtbs/tw6735.pp svneol=native#text/plain
 tests/webtbs/tw6742.pp svneol=native#text/plain

+ 12 - 0
compiler/pdecsub.pas

@@ -896,6 +896,7 @@ implementation
         pd : tprocdef;
         isclassmethod : boolean;
         locationstr: string;
+        popclass : boolean;
       begin
         locationstr:='';
         pd:=nil;
@@ -924,7 +925,18 @@ implementation
                       if try_to_consume(_COLON) then
                        begin
                          inc(testcurobject);
+                         { Add objectsymtable to be able to find generic type definitions }
+                         popclass:=false;
+                         if assigned(pd._class) and
+                            (pd.parast.symtablelevel=normal_function_level) and
+                            (symtablestack.top.symtabletype<>objectsymtable) then
+                           begin
+                             symtablestack.push(pd._class.symtable);
+                             popclass:=true;
+                           end;
                          single_type(pd.rettype,false);
+                         if popclass then
+                           symtablestack.pop(pd._class.symtable);
                          pd.test_if_fpu_result;
                          dec(testcurobject);
 

+ 22 - 0
tests/webtbs/tw6624.pp

@@ -0,0 +1,22 @@
+program project1;
+
+{$mode objfpc}{$H+}
+
+type
+  generic TGenTest1<T> = class
+   public
+    procedure One(const a: T);
+    function Two: T;
+  end;
+
+procedure TGenTest1.One(const a: T);
+begin
+
+end;
+
+function TGenTest1.Two: T; // fails here
+begin
+end;
+
+begin
+end.