Browse Source

* when parsing generic parameter types allow the use of generics that are part of the current specialization stack (this can be the case if a generic is used inside itself as a type parameter for a specialization)
+ added tests

Sven/Sarah Barth 7 months ago
parent
commit
dedc018beb
3 changed files with 43 additions and 0 deletions
  1. 1 0
      compiler/pgenutil.pas
  2. 21 0
      tests/test/tgeneric117.pp
  3. 21 0
      tests/test/tgeneric118.pp

+ 1 - 0
compiler/pgenutil.pas

@@ -594,6 +594,7 @@ uses
             if validparam then
             if validparam then
               begin
               begin
                 if tstoreddef(typeparam.resultdef).is_generic and
                 if tstoreddef(typeparam.resultdef).is_generic and
+                    not is_or_belongs_to_current_genericdef(typeparam.resultdef) and
                     (
                     (
                       not parse_generic or
                       not parse_generic or
                       not defs_belong_to_same_generic(typeparam.resultdef,current_genericdef)
                       not defs_belong_to_same_generic(typeparam.resultdef,current_genericdef)

+ 21 - 0
tests/test/tgeneric117.pp

@@ -0,0 +1,21 @@
+{ %NORUN }
+
+program tgeneric117;
+
+{$mode delphi}
+
+type
+  TTest<T> = class
+  public type
+    TT = ^TTest<T>;
+  end;
+
+  TTest2<T> = class
+  public type
+    TT2 = TTest2<T>;
+    TT = TTest<TT2>;
+  end;
+
+begin
+
+end.

+ 21 - 0
tests/test/tgeneric118.pp

@@ -0,0 +1,21 @@
+{ %NORUN }
+
+program tgeneric117;
+
+{$mode objfpc}
+
+type
+  generic TTest<T> = class
+  public type
+    TT = ^specialize TTest<T>;
+  end;
+
+  generic TTest2<T> = class
+  public type
+    TT2 = specialize TTest2<T>;
+    TT = specialize TTest<TT2>;
+  end;
+
+begin
+
+end.