From 1446ca2fbaeb5e1c94b6d0241a483f31c54c57d0 Mon Sep 17 00:00:00 2001 From: miks1965 Date: Thu, 9 Aug 2018 21:34:26 +0300 Subject: [PATCH] =?UTF-8?q?bug=20fix=20#1029=20ConvertAll=20=D0=B8=20Trans?= =?UTF-8?q?form=20=D1=81=20=D0=B4=D0=BE=D0=BF=D0=BF=D0=B0=D1=80=D0=B0?= =?UTF-8?q?=D0=BC=D0=B5=D1=82=D1=80=D0=B0=D0=BC=D0=B8=20-=20=D0=B8=D0=BD?= =?UTF-8?q?=D0=B4=D0=B5=D0=BA=D1=81=D0=B0=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Configuration/GlobalAssemblyInfo.cs | 2 +- Configuration/Version.defs | 4 +-- ReleaseGenerators/PascalABCNET_version.nsh | 2 +- TestSuite/CompilationSamples/PABCSystem.pas | 32 +++++++++++++++++++++ TestSuite/FunDelNoParamsToObject.pas | 7 +++++ TreeConverter/TreeRealization/type_table.cs | 6 ++++ bin/Lib/PABCSystem.pas | 17 +++++++++++ 7 files changed, 66 insertions(+), 4 deletions(-) create mode 100644 TestSuite/FunDelNoParamsToObject.pas diff --git a/Configuration/GlobalAssemblyInfo.cs b/Configuration/GlobalAssemblyInfo.cs index 651c9c4b4..83de67b53 100644 --- a/Configuration/GlobalAssemblyInfo.cs +++ b/Configuration/GlobalAssemblyInfo.cs @@ -15,7 +15,7 @@ internal static class RevisionClass public const string Major = "3"; public const string Minor = "4"; public const string Build = "0"; - public const string Revision = "1733"; + public const string Revision = "1734"; public const string MainVersion = Major + "." + Minor; public const string FullVersion = Major + "." + Minor + "." + Build + "." + Revision; diff --git a/Configuration/Version.defs b/Configuration/Version.defs index 29be467a2..93975d3fb 100644 --- a/Configuration/Version.defs +++ b/Configuration/Version.defs @@ -1,4 +1,4 @@ -%COREVERSION%=0 -%REVISION%=1733 %MINOR%=4 +%REVISION%=1734 +%COREVERSION%=0 %MAJOR%=3 diff --git a/ReleaseGenerators/PascalABCNET_version.nsh b/ReleaseGenerators/PascalABCNET_version.nsh index e716b79f2..1a13cf22d 100644 --- a/ReleaseGenerators/PascalABCNET_version.nsh +++ b/ReleaseGenerators/PascalABCNET_version.nsh @@ -1 +1 @@ -!define VERSION '3.4.0.1733' +!define VERSION '3.4.0.1734' diff --git a/TestSuite/CompilationSamples/PABCSystem.pas b/TestSuite/CompilationSamples/PABCSystem.pas index 1a780441a..e4b984a0a 100644 --- a/TestSuite/CompilationSamples/PABCSystem.pas +++ b/TestSuite/CompilationSamples/PABCSystem.pas @@ -9057,6 +9057,13 @@ begin Self[i] := f(Self[i]); end; +/// Преобразует элементы массива или списка по заданному правилу +procedure Transform(Self: IList; f: (T,integer)->T); extensionmethod; +begin + for var i := 0 to Self.Count - 1 do + Self[i] := f(Self[i],i); +end; + /// Заполняет элементы массива или списка значениями, вычисляемыми по некоторому правилу procedure Fill(Self: IList; f: integer->T); extensionmethod; begin @@ -9448,6 +9455,15 @@ begin Result[i, j] := converter(Self[i, j]); end; +/// Преобразует элементы двумерного массива и возвращает преобразованный массив +function ConvertAll(Self: array [,] of T; converter: (T,integer,integer)->T1): array [,] of T1; extensionmethod; +begin + Result := new T1[Self.RowCount, Self.ColCount]; + for var i := 0 to Self.RowCount - 1 do + for var j := 0 to Self.ColCount - 1 do + Result[i, j] := converter(Self[i, j],i,j); +end; + /// Преобразует элементы двумерного массива по заданному правилу procedure Transform(Self: array [,] of T; f: T->T); extensionmethod; begin @@ -9456,6 +9472,14 @@ begin Self[i, j] := f(Self[i, j]); end; +/// Преобразует элементы двумерного массива по заданному правилу +procedure Transform(Self: array [,] of T; f: (T,integer,integer)->T); extensionmethod; +begin + for var i := 0 to Self.RowCount - 1 do + for var j := 0 to Self.ColCount - 1 do + Self[i, j] := f(Self[i, j],i,j); +end; + /// Заполняет элементы двумерного массива значениями, вычисляемыми по некоторому правилу procedure Fill(Self: array [,] of T; f: (integer,integer) ->T); extensionmethod; begin @@ -9757,6 +9781,14 @@ begin Result := System.Array.ConvertAll(self, t -> converter(t)); end; +/// Преобразует элементы массива и возвращает преобразованный массив +function ConvertAll(Self: array of T; converter: (T,integer)->T1): array of T1; extensionmethod; +begin + Result := new T1[Self.Length]; + for var i := 0 to Self.Length - 1 do + Result[i] := converter(Self[i],i); +end; + /// Выполняет поиск первого элемента в массиве, удовлетворяющего предикату. Если не найден, возвращается нулевое значение соответствующего типа function Find(Self: array of T; p: T->boolean): T; extensionmethod; begin diff --git a/TestSuite/FunDelNoParamsToObject.pas b/TestSuite/FunDelNoParamsToObject.pas new file mode 100644 index 000000000..0083294de --- /dev/null +++ b/TestSuite/FunDelNoParamsToObject.pas @@ -0,0 +1,7 @@ +function f := 123; + +begin + var ff: ()->integer := f; + var r: object := ff; + Assert(r.Equals(123)); +end. \ No newline at end of file diff --git a/TreeConverter/TreeRealization/type_table.cs b/TreeConverter/TreeRealization/type_table.cs index 518691c93..ced305d0a 100644 --- a/TreeConverter/TreeRealization/type_table.cs +++ b/TreeConverter/TreeRealization/type_table.cs @@ -945,6 +945,8 @@ namespace PascalABCCompiler.TreeRealization { if (dii.return_value_type == to) { + if (ret.first != null) // SSM 09.08.18 + ret.first = null; add_conversion(ret, new convert_types_function_node(convert_delegate_to_return_value_type, true), from, to); } else @@ -953,11 +955,15 @@ namespace PascalABCCompiler.TreeRealization if ((ptcc.first != null) && (ptcc.first.convertion_method != null)) { delegate_type_converter dtc = new delegate_type_converter(ptcc.first.convertion_method); + if (ret.first != null) // SSM 09.08.18 + ret.first = null; add_conversion(ret, new convert_types_function_node(dtc.convert_delegate_to_return_value_type_with_convertion, false), from, to); } if ((ptcc.second != null) && (ptcc.second.convertion_method != null)) { delegate_type_converter dtc = new delegate_type_converter(ptcc.second.convertion_method); + if (ret.first != null) // SSM 09.08.18 + ret.first = null; add_conversion(ret, new convert_types_function_node(dtc.convert_delegate_to_return_value_type_with_convertion, false), from, to); } } diff --git a/bin/Lib/PABCSystem.pas b/bin/Lib/PABCSystem.pas index 982a9951b..e4b984a0a 100644 --- a/bin/Lib/PABCSystem.pas +++ b/bin/Lib/PABCSystem.pas @@ -9455,6 +9455,15 @@ begin Result[i, j] := converter(Self[i, j]); end; +/// Преобразует элементы двумерного массива и возвращает преобразованный массив +function ConvertAll(Self: array [,] of T; converter: (T,integer,integer)->T1): array [,] of T1; extensionmethod; +begin + Result := new T1[Self.RowCount, Self.ColCount]; + for var i := 0 to Self.RowCount - 1 do + for var j := 0 to Self.ColCount - 1 do + Result[i, j] := converter(Self[i, j],i,j); +end; + /// Преобразует элементы двумерного массива по заданному правилу procedure Transform(Self: array [,] of T; f: T->T); extensionmethod; begin @@ -9463,6 +9472,14 @@ begin Self[i, j] := f(Self[i, j]); end; +/// Преобразует элементы двумерного массива по заданному правилу +procedure Transform(Self: array [,] of T; f: (T,integer,integer)->T); extensionmethod; +begin + for var i := 0 to Self.RowCount - 1 do + for var j := 0 to Self.ColCount - 1 do + Self[i, j] := f(Self[i, j],i,j); +end; + /// Заполняет элементы двумерного массива значениями, вычисляемыми по некоторому правилу procedure Fill(Self: array [,] of T; f: (integer,integer) ->T); extensionmethod; begin