[JSCodeGen] 2 issues when using generics
Issue #270
closed
There is 2 issues when using generics:
- external variable field is not taken in account when used in a generic class
- have to add “type” symbole to declare new class after the declaration of a generic class
type
TTest<A> = class external
Field : A; external "field"; //external "field"; here is not taken in account
function Hello(p : A) : A;
end;
type //Need to add "type" here, if not: TTest2 at line 14 will give error: "TTest2 unknown"
TTest2 = class external
Field : Integer; external "field"; //this is taken in account
end;
var i : TTest<Integer>;
var j : TTest<Integer>;
var k : TTest2;
j := i;
j.Field := 10;
PrintLn(j = nil);
k.Field := 16;
This is the output when tested in the “Live scripting demo”
var TObject={
$ClassName: "TObject",
$Parent: null,
ClassName: function (s) { return s.$ClassName },
ClassType: function (s) { return s },
ClassParent: function (s) { return s.$Parent },
$Init: function (s) {},
Create: function (s) { return s },
Destroy: function (s) { for (var prop in s) if (s.hasOwnProperty(prop)) delete s[prop] },
Destroy$: function(s) { return s.ClassType.Destroy(s) },
Free: function (s) { if (s!==null) s.ClassType.Destroy(s) }
}
var Exception={
$ClassName: "Exception",
$Parent: TObject,
$Init: function (s) { s.FMessage="" },
Create: function (s,Msg) { s.FMessage=Msg; return s }
}
function $New(c) { var i={ClassType:c}; c.$Init(i); return i }
function $Check(i,z) { if (i) return i; throw Exception.Create($New(Exception),"Object not instantiated"+z) }
var i = null,
j = null,
k = null;
var $dws = function() {
j = i;
$Check(j," [line: 17, column: 3]").Field = 10;
PrintLn(!j);
$Check(k," [line: 20, column: 3]").field = 16;
}
$dws();
Comments (4)
-
repo owner -
repo owner Fixed by commit 50bab38ce7ff15878577cdb7182987e48d36cf1f
-
reporter Thank you
-
repo owner - changed status to closed
- Log in to comment
The “type” specifier needs to be added before each type declaration in script mode, where you can mix’n match interfaces en implementations, type sections only exist in unit/program/library mode