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

* fix for Mantis #31945: two fixes for nested routines inside generic methods
a) correctly determine whether token recording is required or not (nested routines of generic routines don't need it)
b) correctly determine whether the trailing ";" needs to be parsed (nested routines of generic routines need to)

git-svn-id: trunk@36469 -

svenbarth пре 8 година
родитељ
комит
dffe423b10
3 измењених фајлова са 51 додато и 4 уклоњено
  1. 1 0
      .gitattributes
  2. 10 4
      compiler/psub.pas
  3. 40 0
      tests/webtbs/tw31945.pp

+ 1 - 0
.gitattributes

@@ -15581,6 +15581,7 @@ tests/webtbs/tw3183a.pp svneol=native#text/plain
 tests/webtbs/tw3184.pp svneol=native#text/plain
 tests/webtbs/tw3185.pp svneol=native#text/plain
 tests/webtbs/tw3190.pp svneol=native#text/plain
+tests/webtbs/tw31945.pp svneol=native#text/pascal
 tests/webtbs/tw3197.pp svneol=native#text/plain
 tests/webtbs/tw3207.pp svneol=native#text/plain
 tests/webtbs/tw3210.pp svneol=native#text/plain

+ 10 - 4
compiler/psub.pas

@@ -1877,10 +1877,12 @@ implementation
          entryswitches:=current_settings.localswitches;
 
          recordtokens:=procdef.is_generic or
-                         (
-                           assigned(current_procinfo.procdef.struct) and
-                           (df_generic in current_procinfo.procdef.struct.defoptions)
-                         );
+                       (
+                         assigned(procdef.struct) and
+                         (df_generic in procdef.struct.defoptions) and
+                         assigned(procdef.owner) and
+                         (procdef.owner.defowner=procdef.struct)
+                       );
 
          if recordtokens then
            begin
@@ -2094,6 +2096,10 @@ implementation
             (
               not assigned(current_procinfo.procdef.struct) or
               not (df_specialization in current_procinfo.procdef.struct.defoptions)
+              or not (
+                assigned(current_procinfo.procdef.owner) and
+                (current_procinfo.procdef.owner.defowner=current_procinfo.procdef.struct)
+              )
             ) then
           consume(_SEMICOLON);
 

+ 40 - 0
tests/webtbs/tw31945.pp

@@ -0,0 +1,40 @@
+{ Note: this is a vastly reduced variant of the example attached to bug report #31945 }
+
+unit tw31945;
+
+{$mode objfpc}{$H+}
+
+interface
+
+uses
+  SysUtils;
+
+type
+  { GprAvgLvlTreeNode }
+
+  generic GprAvgLvlTreeNode<T> = class
+  public
+    procedure ConsistencyCheck; virtual;
+  end;
+
+implementation
+
+{ GprAvgLvlTreeNode }
+
+procedure GprAvgLvlTreeNode.ConsistencyCheck;
+
+  procedure E(Msg: string);
+  begin
+    raise Exception.Create('GprAvgLvlTreeNode.ConsistencyCheck: '+Msg);
+  end;
+
+begin
+  E('Hello World');
+end;
+
+var
+  t: specialize GprAvgLvlTreeNode<LongInt>;
+initialization
+
+end.
+