pas2js: fixed assign record with field of dynamic array

This commit is contained in:
mattias 2020-07-08 09:31:34 +00:00
parent a2f314b267
commit a27c404501
2 changed files with 23 additions and 19 deletions

View File

@ -15394,7 +15394,10 @@ begin
// clone sub static array
VarAssignSt.Expr:=CreateCloneStaticArray(PasVar,TPasArrayType(PasVarType),
SrcExpr,aContext);
end;
end
else
// reference dynamic array
VarAssignSt.Expr:=CreateArrayRef(PasVar,SrcExpr);
end
else if PasVarClass=TPasSetType then
begin
@ -22473,12 +22476,9 @@ begin
PasVarType:=aResolver.ResolveAliasType(PasVar.VarType);
if PasVarType.ClassType=TPasArrayType then
begin
if length(TPasArrayType(PasVarType).Ranges)>0 then
begin
// sub static array
NewFields.Add(PasVar);
continue;
end;
// sub array
NewFields.Add(PasVar);
continue;
end
else if PasVarType.ClassType=TPasRecordType then
begin

View File

@ -10456,9 +10456,9 @@ begin
'rtl.recNewT($mod, "TBigRec", function () {',
' this.Int = 0;',
' this.D = 0.0;',
' this.Arr = [];',
' this.$new = function () {',
' var r = Object.create(this);',
' r.Arr = [];',
' r.Arr2 = rtl.arraySetLength(null, 0, 2);',
' r.Small = $mod.TSmallRec.$new();',
' r.Enums = {};',
@ -10470,7 +10470,7 @@ begin
' this.$assign = function (s) {',
' this.Int = s.Int;',
' this.D = s.D;',
' this.Arr = s.Arr;',
' this.Arr = rtl.arrayRef(s.Arr);',
' this.Arr2 = s.Arr2.slice(0);',
' this.Small.$assign(s.Small);',
' this.Enums = rtl.refSet(s.Enums);',
@ -10925,9 +10925,9 @@ begin
CheckSource('TestRecord_FieldArray',
LinesToStr([ // statements
'rtl.recNewT($mod, "TRec", function () {',
' this.a = [];',
' this.$new = function () {',
' var r = Object.create(this);',
' r.a = [];',
' r.s = rtl.arraySetLength(null, 0, 2);',
' r.m = rtl.arraySetLength(null, 0, 2, 2);',
' r.o = rtl.arraySetLength(null, 0, 2);',
@ -10937,7 +10937,7 @@ begin
' return (this.a === b.a) && rtl.arrayEq(this.s, b.s) && rtl.arrayEq(this.m, b.m) && rtl.arrayEq(this.o, b.o);',
' };',
' this.$assign = function (s) {',
' this.a = s.a;',
' this.a = rtl.arrayRef(s.a);',
' this.s = s.s.slice(0);',
' this.m = s.m.slice(0);',
' this.o = s.o.slice(0);',
@ -10991,9 +10991,9 @@ begin
'});',
'rtl.recNewT($mod, "TRec", function () {',
' this.i = 0;',
' this.a = [];',
' this.$new = function () {',
' var r = Object.create(this);',
' r.a = [];',
' r.s = rtl.arraySetLength(null, 0, 2);',
' r.m = rtl.arraySetLength(null, 0, 2, 2);',
' r.p = $mod.TPoint.$new();',
@ -11004,7 +11004,7 @@ begin
' };',
' this.$assign = function (s) {',
' this.i = s.i;',
' this.a = s.a;',
' this.a = rtl.arrayRef(s.a);',
' this.s = s.s.slice(0);',
' this.m = s.m.slice(0);',
' this.p.$assign(s.p);',
@ -11400,9 +11400,9 @@ begin
'}, true);',
'rtl.recNewT($mod, "TRec", function () {',
' this.i = 0;',
' this.a = [];',
' this.$new = function () {',
' var r = Object.create(this);',
' r.a = [];',
' r.s = rtl.arraySetLength(null, 0, 2);',
' r.m = rtl.arraySetLength(null, 0, 2, 2);',
' r.p = $mod.TPoint.$new();',
@ -11413,7 +11413,7 @@ begin
' };',
' this.$assign = function (s) {',
' this.i = s.i;',
' this.a = s.a;',
' this.a = rtl.arrayRef(s.a);',
' this.s = s.s.slice(0);',
' this.m = s.m.slice(0);',
' this.p.$assign(s.p);',
@ -28683,14 +28683,18 @@ begin
CheckSource('TestRTTI_Record',
LinesToStr([ // statements
'rtl.recNewT($mod, "TFloatRec", function () {',
' this.c = [];',
' this.d = [];',
' this.$new = function () {',
' var r = Object.create(this);',
' r.c = [];',
' r.d = [];',
' return r;',
' };',
' this.$eq = function (b) {',
' return (this.c === b.c) && (this.d === b.d);',
' };',
' this.$assign = function (s) {',
' this.c = s.c;',
' this.d = s.d;',
' this.c = rtl.arrayRef(s.c);',
' this.d = rtl.arrayRef(s.d);',
' return this;',
' };',
' $mod.$rtti.$DynArray("TFloatRec.d$a", {',