From c0040271c94e50b7c2abba238662637b37b3c9a3 Mon Sep 17 00:00:00 2001 From: Mattias Gaertner Date: Wed, 4 Nov 2020 23:13:04 +0000 Subject: [PATCH] pastojs: filer: generic constraints git-svn-id: trunk@47319 - (cherry picked from commit b308412a370d2d08427a683eb58a22bb0191e83d) --- packages/pastojs/src/pas2jsfiler.pp | 4 +-- packages/pastojs/tests/tcfiler.pas | 39 +++++++++++++++++++++++------ 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/packages/pastojs/src/pas2jsfiler.pp b/packages/pastojs/src/pas2jsfiler.pp index 96c647405c..03fd001864 100644 --- a/packages/pastojs/src/pas2jsfiler.pp +++ b/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; diff --git a/packages/pastojs/tests/tcfiler.pas b/packages/pastojs/tests/tcfiler.pas index db9489bcba..535d0ea2ca 100644 --- a/packages/pastojs/tests/tcfiler.pas +++ b/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 = class a: TAnt; end; // ToDo: no specialize: TBird = class a: TBird; 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 = class', + ' end;', + ' TEagle = class', + ' end;', + ' TAnt = class', + ' end;', + ' TFish = class end;', + ' TBirdFish = TBird;', + ' TAntFish = TAnt;', + ' TWater = class', + ' end;', + ' TRec = record end;', + 'var', + ' bf: TBirdFish;', + ' af: TAntFish;', + ' er: TEagle;', + ' wf: TWater;', + 'implementation', + '']); + WriteReadUnit; +end; + procedure TTestPrecompile.TestPC_UseUnit; begin AddModuleWithIntfImplSrc('unit2.pp',