From 48f2ed4967b636d43ce6ec1a1c56c11082df550d Mon Sep 17 00:00:00 2001 From: Ivan Bondarev Date: Tue, 26 Oct 2021 20:38:19 +0200 Subject: [PATCH] #2552 --- TestSuite/implicitexplicit17.pas | 19 +++++++++++++++++++ TestSuite/implicitexplicit18.pas | 26 ++++++++++++++++++++++++++ TreeConverter/TreeRealization/types.cs | 4 ++++ 3 files changed, 49 insertions(+) create mode 100644 TestSuite/implicitexplicit17.pas create mode 100644 TestSuite/implicitexplicit18.pas diff --git a/TestSuite/implicitexplicit17.pas b/TestSuite/implicitexplicit17.pas new file mode 100644 index 000000000..f9fa98b41 --- /dev/null +++ b/TestSuite/implicitexplicit17.pas @@ -0,0 +1,19 @@ +type + t1 = class + i, j: integer; + static function operator implicit(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. \ No newline at end of file diff --git a/TestSuite/implicitexplicit18.pas b/TestSuite/implicitexplicit18.pas new file mode 100644 index 000000000..d9e43989f --- /dev/null +++ b/TestSuite/implicitexplicit18.pas @@ -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(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. \ No newline at end of file diff --git a/TreeConverter/TreeRealization/types.cs b/TreeConverter/TreeRealization/types.cs index 6e4770a16..cd993924f 100644 --- a/TreeConverter/TreeRealization/types.cs +++ b/TreeConverter/TreeRealization/types.cs @@ -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(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(new type_node[] { ctn }), false, null); if (fn == null) continue;