瀏覽代碼

pastojs: skip generic type

git-svn-id: trunk@42524 -
Mattias Gaertner 6 年之前
父節點
當前提交
847ac91d1d

+ 1 - 0
.gitattributes

@@ -8156,6 +8156,7 @@ packages/pastojs/src/pas2jsuseanalyzer.pp svneol=native#text/plain
 packages/pastojs/src/pas2jsutils.pp svneol=native#text/plain
 packages/pastojs/src/pas2jsutils.pp svneol=native#text/plain
 packages/pastojs/tests/tcconverter.pp svneol=native#text/plain
 packages/pastojs/tests/tcconverter.pp svneol=native#text/plain
 packages/pastojs/tests/tcfiler.pas svneol=native#text/plain
 packages/pastojs/tests/tcfiler.pas svneol=native#text/plain
+packages/pastojs/tests/tcgenerics.pas svneol=native#text/plain
 packages/pastojs/tests/tcmodules.pas svneol=native#text/plain
 packages/pastojs/tests/tcmodules.pas svneol=native#text/plain
 packages/pastojs/tests/tcoptimizations.pas svneol=native#text/plain
 packages/pastojs/tests/tcoptimizations.pas svneol=native#text/plain
 packages/pastojs/tests/tcprecompile.pas svneol=native#text/plain
 packages/pastojs/tests/tcprecompile.pas svneol=native#text/plain

+ 9 - 0
packages/pastojs/src/fppas2js.pp

@@ -13326,6 +13326,9 @@ var
   aResolver: TPas2JSResolver;
   aResolver: TPas2JSResolver;
 begin
 begin
   Result:=nil;
   Result:=nil;
+  if (El.GenericTemplateTypes<>nil) and (El.GenericTemplateTypes.Count>0) then
+    exit;
+
   {$IFDEF VerbosePas2JS}
   {$IFDEF VerbosePas2JS}
   writeln('TPasToJSConverter.ConvertClassType START ',GetObjName(El));
   writeln('TPasToJSConverter.ConvertClassType START ',GetObjName(El));
   {$ENDIF}
   {$ENDIF}
@@ -13983,6 +13986,8 @@ var
   Prop: TJSObjectLiteralElement;
   Prop: TJSObjectLiteralElement;
 begin
 begin
   Result:=nil;
   Result:=nil;
+  if (El.GenericTemplateTypes<>nil) and (El.GenericTemplateTypes.Count>0) then
+    exit;
   if El.IsNested then
   if El.IsNested then
     DoError(20170222231636,nPasElementNotSupported,sPasElementNotSupported,
     DoError(20170222231636,nPasElementNotSupported,sPasElementNotSupported,
       ['is nested'],El);
       ['is nested'],El);
@@ -14106,6 +14111,8 @@ var
   ReturnSt: TJSReturnStatement;
   ReturnSt: TJSReturnStatement;
 begin
 begin
   Result:=nil;
   Result:=nil;
+  if (El.GenericTemplateTypes<>nil) and (El.GenericTemplateTypes.Count>0) then
+    exit;
   if El.PackMode<>pmNone then
   if El.PackMode<>pmNone then
     DoError(20170222231648,nPasElementNotSupported,sPasElementNotSupported,
     DoError(20170222231648,nPasElementNotSupported,sPasElementNotSupported,
        ['packed'],El);
        ['packed'],El);
@@ -22860,6 +22867,8 @@ var
   VarSt: TJSVariableStatement;
   VarSt: TJSVariableStatement;
 begin
 begin
   Result:=nil;
   Result:=nil;
+  if (El.GenericTemplateTypes<>nil) and (El.GenericTemplateTypes.Count>0) then
+    exit;
   if El.Name='' then
   if El.Name='' then
     RaiseNotSupported(El,AContext,20190105101258,'anonymous record');
     RaiseNotSupported(El,AContext,20190105101258,'anonymous record');
   {$IFDEF VerbosePas2JS}
   {$IFDEF VerbosePas2JS}

+ 56 - 0
packages/pastojs/tests/tcgenerics.pas

@@ -0,0 +1,56 @@
+unit TCGenerics;
+
+{$mode objfpc}{$H+}
+
+interface
+
+uses
+  Classes, SysUtils, fpcunit, testregistry,
+  TCModules;
+
+type
+
+  { TTestGenerics }
+
+  TTestGenerics = class(TCustomTestModule)
+  Published
+    Procedure TestGeneric_RecordEmpty;
+  end;
+
+implementation
+
+{ TTestGenerics }
+
+procedure TTestGenerics.TestGeneric_RecordEmpty;
+begin
+  StartProgram(false);
+  Add([
+  'type',
+  '  generic TRecA<T> = record',
+  '  end;',
+  'var a,b: specialize TRecA<word>;',
+  'begin',
+  '  if a=b then ;']);
+  ConvertProgram;
+  CheckSource('TestGeneric_RecordEmpty',
+    LinesToStr([ // statements
+    'rtl.recNewT($mod, "TRecA$G1", function () {',
+    '  this.$eq = function (b) {',
+    '    return true;',
+    '  };',
+    '  this.$assign = function (s) {',
+    '    return this;',
+    '  };',
+    '});',
+    'this.a = $mod.TRecA$G1.$new();',
+    'this.b = $mod.TRecA$G1.$new();',
+    '']),
+    LinesToStr([ // $mod.$main
+    'if ($mod.a.$eq($mod.b)) ;'
+    ]));
+end;
+
+Initialization
+  RegisterTests([TTestGenerics]);
+end.
+

+ 6 - 1
packages/pastojs/tests/testpas2js.lpi

@@ -37,7 +37,7 @@
         <PackageName Value="FCL"/>
         <PackageName Value="FCL"/>
       </Item2>
       </Item2>
     </RequiredPackages>
     </RequiredPackages>
-    <Units Count="12">
+    <Units Count="13">
       <Unit0>
       <Unit0>
         <Filename Value="testpas2js.pp"/>
         <Filename Value="testpas2js.pp"/>
         <IsPartOfProject Value="True"/>
         <IsPartOfProject Value="True"/>
@@ -93,6 +93,11 @@
         <IsPartOfProject Value="True"/>
         <IsPartOfProject Value="True"/>
         <UnitName Value="Pas2jsUseAnalyzer"/>
         <UnitName Value="Pas2jsUseAnalyzer"/>
       </Unit11>
       </Unit11>
+      <Unit12>
+        <Filename Value="tcgenerics.pas"/>
+        <IsPartOfProject Value="True"/>
+        <UnitName Value="TCGenerics"/>
+      </Unit12>
     </Units>
     </Units>
   </ProjectOptions>
   </ProjectOptions>
   <CompilerOptions>
   <CompilerOptions>

+ 2 - 2
packages/pastojs/tests/testpas2js.pp

@@ -20,8 +20,8 @@ uses
   {$IFDEF EnableMemCheck}
   {$IFDEF EnableMemCheck}
   MemCheck,
   MemCheck,
   {$ENDIF}
   {$ENDIF}
-  Classes, consoletestrunner, tcconverter, tcmodules, tcoptimizations, tcsrcmap,
-  tcfiler, Pas2JsFiler, tcunitsearch, tcprecompile, pas2jsuseanalyzer;
+  Classes, consoletestrunner, tcconverter, TCModules, tcoptimizations, tcsrcmap,
+  tcfiler, tcunitsearch, tcprecompile, TCGenerics;
 
 
 type
 type