Browse Source

pastojs: filer: read inline specialize expr

git-svn-id: trunk@47673 -
Mattias Gaertner 4 years ago
parent
commit
7b223eafe1
2 changed files with 32 additions and 6 deletions
  1. 8 6
      packages/pastojs/src/pas2jsfiler.pp
  2. 24 0
      packages/pastojs/tests/tcfiler.pas

+ 8 - 6
packages/pastojs/src/pas2jsfiler.pp

@@ -8368,17 +8368,18 @@ begin
     if El.Params[i]=nil then
       RaiseMsg(20200512232836,El,GetObjPath(El.DestType)+' Params['+IntToStr(i)+']=nil');
 
-  // El.Data TPasSpecializeTypeData
-  Data:=TPasSpecializeTypeData.Create;
-  // add to free list
-  Resolver.AddResolveData(El,Data,lkModule);
-
   if not ReadInteger(Obj,'SpecType',SpecId,El) then
     begin
-    if Obj.Find('SpecType')=nil then
+    if Obj.Find('SpecType')<>nil then
       RaiseMsg(20201203092759,El,GetObjName(Obj.Find('SpecType')));
+    exit; // generic reference to a generic
     end;
 
+  // El.Data TPasSpecializeTypeData
+  Data:=TPasSpecializeTypeData.Create;
+  // add to free list
+  Resolver.AddResolveData(El,Data,lkModule);
+
   PromiseSetElReference(SpecId,@Set_SpecializeTypeData,Data,El);
 
   // check old specialized name
@@ -8400,6 +8401,7 @@ procedure TPCUReader.ReadInlineSpecializeExpr(Obj: TJSONObject;
 var
   Parent: TPasElement;
 begin
+  ReadPasElement(Obj,Expr,aContext);
   Expr.Kind:=pekSpecialize;
   Expr.NameExpr:=ReadExpr(Obj,Expr,'SpecName',aContext);
   ReadElementList(Obj,Expr,'SpecParams',Expr.Params,

+ 24 - 0
packages/pastojs/tests/tcfiler.pas

@@ -233,6 +233,7 @@ type
     procedure TestPC_Constraints;
     // ToDo: constraints
     // ToDo: unit impl declarations used by generics
+    procedure TestPC_GenericClass_InlineSpecialize;
 
     procedure TestPC_UseUnit;
     procedure TestPC_UseUnit_Class;
@@ -3530,6 +3531,29 @@ begin
   WriteReadUnit;
 end;
 
+procedure TTestPrecompile.TestPC_GenericClass_InlineSpecialize;
+begin
+  StartUnit(true,[supTObject]);
+  Add([
+  '{$mode delphi}',
+  'interface',
+  'type',
+  '  TBird<T: class> = class',
+  '  end;',
+  '  TEagle<T: class> = class(TBird<T>)',
+  '  type',
+  '    TMyEagle = TEagle<T>;',
+  '    function Fly(v: T): T;',
+  '  end;',
+  'implementation',
+  'function TEagle<T>.Fly(v: T): T;',
+  'begin',
+  '  TEagle<T>.Create;',
+  'end;',
+  '']);
+  WriteReadUnit;
+end;
+
 procedure TTestPrecompile.TestPC_UseUnit;
 begin
   AddModuleWithIntfImplSrc('unit2.pp',