This commit is contained in:
Ivan Bondarev 2021-10-26 20:38:19 +02:00
parent 2d2798c711
commit 48f2ed4967
3 changed files with 49 additions and 0 deletions

View file

@ -0,0 +1,19 @@
type
t1 = class
i, j: integer;
static function operator implicit<T>(a: array of T): t1; where T: record;
begin
var obj := new t1;
obj.i := integer(object(a[0]));
obj.j := integer(object(a[1]));
Result := obj;
end;
end;
begin
var a := Arr(1,2);
var b: t1 := a;
assert(b.i = 1);
assert(b.j = 2);
end.

View file

@ -0,0 +1,26 @@
type
TRec = record
i: integer;
constructor(i: integer);
begin
self.i := i;
end;
end;
t1 = class
i, j: integer;
static function operator implicit<T>(a: array of T): t1; where T: record;
begin
var obj := new t1;
obj.i := TRec(object(a[0])).i;
obj.j := TRec(object(a[1])).i;
Result := obj;
end;
end;
begin
var a := Arr(new TRec(1),new TRec(2));
var b: t1 := a;
assert(b.i = 1);
assert(b.j = 2);
end.

View file

@ -2387,6 +2387,8 @@ namespace PascalABCCompiler.TreeRealization
{
if (ctn.IsPointer)
continue;
if (ctn.type_special_kind == SemanticTree.type_special_kind.array_kind)
ctn = ctn.element_type;
fn = fn.get_instance(new List<type_node>(new type_node[] { ctn }), false, null);
if (fn == null)
continue;
@ -2433,6 +2435,8 @@ namespace PascalABCCompiler.TreeRealization
ctn = (ctn as ref_type_node).pointed_type;
if (ctn.IsPointer)
continue;
if (ctn.type_special_kind == SemanticTree.type_special_kind.array_kind)
ctn = ctn.element_type;
fn = fn.get_instance(new List<type_node>(new type_node[] { ctn }), false, null);
if (fn == null)
continue;