Просмотр исходного кода

* allow type parameters in variant parts of records as we do not now
what type is used during specialization, resolves #39805

florian 3 лет назад
Родитель
Сommit
ceda27ae25
4 измененных файлов с 30 добавлено и 5 удалено
  1. 1 4
      compiler/pdecvar.pas
  2. 0 1
      tests/test/tgeneric26.pp
  3. 16 0
      tests/webtbf/tw39805b.pp
  4. 13 0
      tests/webtbs/tw39805a.pp

+ 1 - 4
compiler/pdecvar.pas

@@ -1822,10 +1822,7 @@ implementation
                classes are allowed }
              if (variantrecordlevel>0) then
                if is_managed_type(hdef) then
-                 Message(parser_e_cant_use_inittable_here)
-               else
-               if hdef.typ=undefineddef then
-                 Message(parser_e_cant_use_type_parameters_here);
+                 Message(parser_e_cant_use_inittable_here);
 
              { try to parse the hint directives }
              hintsymoptions:=[];

+ 0 - 1
tests/test/tgeneric26.pp

@@ -1,4 +1,3 @@
-{ %fail }
 program tgeneric26;
 
 {$mode objfpc}{$H+}

+ 16 - 0
tests/webtbf/tw39805b.pp

@@ -0,0 +1,16 @@
+{ %fail }
+program Project1;
+{$mode objfpc}{$H+}
+const
+  ts=3;
+type
+  generic GTest<T>=record
+    case byte of
+    0:(ta:array [0..2] of T);
+    1:(t1:T;t2:T;t3:T);
+  end;
+
+  TTestVariant = specialize GTest<Variant>;
+
+begin
+end. 

+ 13 - 0
tests/webtbs/tw39805a.pp

@@ -0,0 +1,13 @@
+program Project1;
+{$mode objfpc}{$H+}
+const
+  ts=3;
+type
+  generic GTest<T>=record
+    case byte of
+    0:(ta:array [0..2] of T);
+    1:(t1:T;t2:T;t3:T);
+  end;
+
+begin
+end.