From 222f3d981f91f549fddc9f9b53a03a1126191730 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D0=BE=D0=BD=D0=B4=D0=B0=D1=80=D0=B5=D0=B2=20=D0=98?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD?= Date: Thu, 4 Jul 2019 22:05:57 +0200 Subject: [PATCH] bug fix #1847 --- NETGenerator/NETGenegratorTools.cs | 2 ++ NETGenerator/NETGenerator.cs | 4 ++-- TestSuite/generics28.pas | 13 +++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 TestSuite/generics28.pas diff --git a/NETGenerator/NETGenegratorTools.cs b/NETGenerator/NETGenegratorTools.cs index ddf947e36..f4cae332a 100644 --- a/NETGenerator/NETGenegratorTools.cs +++ b/NETGenerator/NETGenegratorTools.cs @@ -47,6 +47,7 @@ namespace PascalABCCompiler.NETGenerator public static Type GCHandleType = typeof(GCHandle); public static Type MarshalType = typeof(Marshal); public static Type TypeType = typeof(Type); + public static Type ValueType = typeof(ValueType); public static Type IEnumerableType = typeof(System.Collections.IEnumerable); public static Type IEnumeratorType = typeof(System.Collections.IEnumerator); public static Type IEnumerableGenericType = typeof(System.Collections.Generic.IEnumerable<>); @@ -110,6 +111,7 @@ namespace PascalABCCompiler.NETGenerator sizes[UInt64Type] = sizeof(UInt64); sizes[SingleType] = sizeof(Single); sizes[DoubleType] = sizeof(Double); + //sizes[UIntPtr] = sizeof(UIntPtr); //types[TypeType] = TypeType; ArrayCopyMethod = typeof(Array).GetMethod("Copy", new Type[3] { typeof(Array), typeof(Array), typeof(int) }); diff --git a/NETGenerator/NETGenerator.cs b/NETGenerator/NETGenerator.cs index eef16fd34..12cec9214 100644 --- a/NETGenerator/NETGenerator.cs +++ b/NETGenerator/NETGenerator.cs @@ -1132,7 +1132,6 @@ namespace PascalABCCompiler.NETGenerator if (ctn != null) throw new PascalABCCompiler.Errors.CommonCompilerError(ex.Message, ctn.Location.document.file_name, ctn.Location.begin_line_num, ctn.Location.begin_column_num); } - } for (int i = 0; i < enums.Count; i++) @@ -1325,7 +1324,7 @@ namespace PascalABCCompiler.NETGenerator private void AddTypeWithoutConvert(ICommonTypeNode t) { if (helper.GetTypeReference(t) != null) return; - TypeBuilder tb = mb.DefineType(BuildTypeName(t.name), ConvertAttributes(t), null, new Type[0]); + TypeBuilder tb = mb.DefineType(BuildTypeName(t.name), ConvertAttributes(t), t.is_value_type?TypeFactory.ValueType:null, new Type[0]); helper.AddType(t, tb); //(ssyy) обрабатываем generics if (t.is_generic_type_definition) @@ -6660,6 +6659,7 @@ namespace PascalABCCompiler.NETGenerator if (value.is_final) { + attrs |= MethodAttributes.Virtual | MethodAttributes.Final; } diff --git a/TestSuite/generics28.pas b/TestSuite/generics28.pas new file mode 100644 index 000000000..84611a059 --- /dev/null +++ b/TestSuite/generics28.pas @@ -0,0 +1,13 @@ +type + SomeType = record(IComparable) + public + function CompareTo(other: SomeType): integer; + begin + Result := 2; + end; + end; + +begin + var obj := new SomeType(); + assert(obj.CompareTo(obj) = 2); +end. \ No newline at end of file