Browse Source

pastojs: filer: generic constraints

git-svn-id: trunk@47319 -
Mattias Gaertner 4 years ago
parent
commit
b308412a37
2 changed files with 33 additions and 10 deletions
  1. 2 2
      packages/pastojs/src/pas2jsfiler.pp
  2. 31 8
      packages/pastojs/tests/tcfiler.pas

+ 2 - 2
packages/pastojs/src/pas2jsfiler.pp

@@ -3978,7 +3978,7 @@ begin
     TemplObj:=TJSONObject.Create;
     Arr.Add(TemplObj);
     WritePasElement(TemplObj,Templ,aContext);
-    WriteElementArray(TemplObj,Parent,'Constraints',Templ.Constraints,aContext,true);
+    WriteElementArray(TemplObj,Templ,'Constraints',Templ.Constraints,aContext,true);
     end;
 end;
 
@@ -8203,7 +8203,7 @@ begin
     GenType:=TPasGenericTemplateType(CreateElement(TPasGenericTemplateType,GenTypeName,Parent));
     GenericTemplateTypes.Add(GenType);
     ReadPasElement(TemplObj,GenType,aContext);
-    ReadElementArray(TemplObj,Parent,'Constraints',GenType.Constraints,
+    ReadElementArray(TemplObj,GenType,'Constraints',GenType.Constraints,
       {$IFDEF CheckPasTreeRefCount}'TPasGenericTemplateType.Constraints'{$ELSE}true{$ENDIF},
       aContext);
     end;

+ 31 - 8
packages/pastojs/tests/tcfiler.pas

@@ -228,17 +228,11 @@ type
     procedure TestPC_InlineSpecialize_LocalTypeInUnit;
     procedure TestPC_Specialize_Array;
     procedure TestPC_Specialize_ProcType;
-    // ToDo: specialize extern generic type in unit interface
-    // ToDo: specialize extern generic type in unit implementation
-    // ToDo: specialize extern generic type in proc decl
-    // ToDo: specialize extern generic type in proc body
-    // ToDo: inline specialize extern generic type in unit interface
-    // ToDo: inline specialize extern generic type in unit implementation
-    // ToDo: inline specialize extern generic type in proc decl
-    // ToDo: inline specialize extern generic type in proc body
     // ToDo: half specialize TBird<T> = class a: TAnt<word,T>; end;
     // ToDo: no specialize: TBird<T> = class a: TBird<T>; end;
+    procedure TestPC_Constraints;
     // ToDo: constraints
+    // ToDo: unit impl declarations used by generics
 
     procedure TestPC_UseUnit;
     procedure TestPC_UseUnit_Class;
@@ -3507,6 +3501,35 @@ begin
   WriteReadUnit;
 end;
 
+procedure TTestPrecompile.TestPC_Constraints;
+begin
+  StartUnit(true,[supTObject]);
+  Add([
+  '{$mode delphi}',
+  'interface',
+  'type',
+  '  TBird<T: class> = class',
+  '  end;',
+  '  TEagle<T: record> = class',
+  '  end;',
+  '  TAnt<T: constructor> = class',
+  '  end;',
+  '  TFish = class end;',
+  '  TBirdFish = TBird<TFish>;',
+  '  TAntFish = TAnt<TFish>;',
+  '  TWater<T: TFish> = class',
+  '  end;',
+  '  TRec = record end;',
+  'var',
+  '  bf: TBirdFish;',
+  '  af: TAntFish;',
+  '  er: TEagle<TRec>;',
+  '  wf: TWater<TFish>;',
+  'implementation',
+  '']);
+  WriteReadUnit;
+end;
+
 procedure TTestPrecompile.TestPC_UseUnit;
 begin
   AddModuleWithIntfImplSrc('unit2.pp',