summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormattias <mattias@3ad0048d-3df7-0310-abae-a5850022a9f2>2021-04-24 10:55:03 +0000
committermattias <mattias@3ad0048d-3df7-0310-abae-a5850022a9f2>2021-04-24 10:55:03 +0000
commit46654882fa21eb8cd56ca1720cf81c265a75bb7e (patch)
treebddcf886a09a4fc17c55cc141d75a2e7a8c7c650
parent16ed3e2dca27a0ad4100396b4d2bf967bbe3bd91 (diff)
downloadfpc-46654882fa21eb8cd56ca1720cf81c265a75bb7e.tar.gz
pastojs: specialize try except on, issue 38795
git-svn-id: https://svn.freepascal.org/svn/fpc/trunk@49253 3ad0048d-3df7-0310-abae-a5850022a9f2
-rw-r--r--packages/fcl-passrc/tests/tcresolvegenerics.pas1
-rw-r--r--packages/pastojs/src/fppas2js.pp5
-rw-r--r--packages/pastojs/tests/tcgenerics.pas72
3 files changed, 77 insertions, 1 deletions
diff --git a/packages/fcl-passrc/tests/tcresolvegenerics.pas b/packages/fcl-passrc/tests/tcresolvegenerics.pas
index 83f59c6c7c..8c39552070 100644
--- a/packages/fcl-passrc/tests/tcresolvegenerics.pas
+++ b/packages/fcl-passrc/tests/tcresolvegenerics.pas
@@ -157,6 +157,7 @@ type
procedure TestGenProc_TypeParamCntOverloadNoParams;
procedure TestGenProc_TypeParamWithDefaultParamDelphiFail;
procedure TestGenProc_ParamSpecWithT;
+ // ToDo: TestGenProc_ParamSpecWithTNestedType function Fly<T>(a: TBird<T>.TEvent; aSender: T): Word;
// ToDo: NestedResultAssign
// generic function infer types
diff --git a/packages/pastojs/src/fppas2js.pp b/packages/pastojs/src/fppas2js.pp
index bb222fd720..2054885b0d 100644
--- a/packages/pastojs/src/fppas2js.pp
+++ b/packages/pastojs/src/fppas2js.pp
@@ -4488,6 +4488,9 @@ begin
AddElevatedLocal(El);
end;
end
+ else if ParentC=TPasImplExceptOn then
+ // except on var
+ RaiseVarModifierNotSupported(LocalVarModifiersAllowed)
else if ParentC=TImplementationSection then
// implementation var
RaiseVarModifierNotSupported(ImplementationVarModifiersAllowed)
@@ -4499,7 +4502,7 @@ begin
else
begin
{$IFDEF VerbosePas2JS}
- writeln('TPas2JSResolver.FinishVariable ',GetObjName(El),' Parent=',GetObjName(El.Parent));
+ writeln('TPas2JSResolver.FinishVariable ',GetObjPath(El));
{$ENDIF}
RaiseNotYetImplemented(20170324151259,El);
end;
diff --git a/packages/pastojs/tests/tcgenerics.pas b/packages/pastojs/tests/tcgenerics.pas
index 8b1c961aa3..ff46fbe342 100644
--- a/packages/pastojs/tests/tcgenerics.pas
+++ b/packages/pastojs/tests/tcgenerics.pas
@@ -62,6 +62,7 @@ type
Procedure TestGen_CallUnitImplProc;
Procedure TestGen_IntAssignTemplVar;
Procedure TestGen_TypeCastDotField;
+ Procedure TestGen_Except;
// generic helper
procedure TestGen_HelperForArray;
@@ -1950,6 +1951,77 @@ begin
'']));
end;
+procedure TTestGenerics.TestGen_Except;
+begin
+ StartProgram(false);
+ Add([
+ 'type',
+ ' TObject = class end;',
+ ' generic TBird<T> = class',
+ ' Field: T;',
+ ' procedure Fly;',
+ ' end;',
+ ' Exception = class',
+ ' end;',
+ ' generic EBird<T> = class(Exception)',
+ ' Id: T;',
+ ' end;',
+ 'var',
+ ' b: specialize TBird<word>;',
+ 'procedure TBird.Fly;',
+ 'begin',
+ ' try',
+ ' except',
+ ' on E: Exception do Fly;',
+ ' on EBird: specialize EBird<word> do EBird.Id:=3;',
+ ' else',
+ ' Fly;',
+ ' end;',
+ 'end;',
+ 'begin',
+ '']);
+ ConvertProgram;
+ CheckSource('TestGen_Except',
+ LinesToStr([ // statements
+ 'rtl.createClass(this, "TObject", null, function () {',
+ ' this.$init = function () {',
+ ' };',
+ ' this.$final = function () {',
+ ' };',
+ '});',
+ 'rtl.createClass(this, "Exception", this.TObject, function () {',
+ '});',
+ 'rtl.createClass(this, "TBird$G1", this.TObject, function () {',
+ ' this.$init = function () {',
+ ' $mod.TObject.$init.call(this);',
+ ' this.Field = 0;',
+ ' };',
+ ' this.Fly = function () {',
+ ' try {} catch ($e) {',
+ ' if ($mod.Exception.isPrototypeOf($e)) {',
+ ' var E = $e;',
+ ' this.Fly();',
+ ' } else if ($mod.EBird$G1.isPrototypeOf($e)) {',
+ ' var EBird = $e;',
+ ' EBird.Id = 3;',
+ ' } else {',
+ ' this.Fly();',
+ ' }',
+ ' };',
+ ' };',
+ '}, "TBird<System.Word>");',
+ 'this.b = null;',
+ 'rtl.createClass(this, "EBird$G1", this.Exception, function () {',
+ ' this.$init = function () {',
+ ' $mod.Exception.$init.call(this);',
+ ' this.Id = 0;',
+ ' };',
+ '}, "EBird<System.Word>");',
+ '']),
+ LinesToStr([ // $mod.$main
+ '']));
+end;
+
procedure TTestGenerics.TestGen_HelperForArray;
begin
StartProgram(false);