From 1e7163e211efc35771a926a36550ed7734a8bdd3 Mon Sep 17 00:00:00 2001 From: Ivan Bondarev Date: Sat, 1 Jan 2022 14:04:50 +0100 Subject: [PATCH] #2599 --- NETGenerator/NETGenerator.cs | 35 ++++++++++++++++++++++++----------- TestSuite/genericrecords4.pas | 13 +++++++++++++ 2 files changed, 37 insertions(+), 11 deletions(-) create mode 100644 TestSuite/genericrecords4.pas diff --git a/NETGenerator/NETGenerator.cs b/NETGenerator/NETGenerator.cs index 224ccabe1..e5a657617 100644 --- a/NETGenerator/NETGenerator.cs +++ b/NETGenerator/NETGenerator.cs @@ -1291,6 +1291,7 @@ namespace PascalABCCompiler.NETGenerator for (int i = 0; i < enums.Count; i++) enums[i].CreateType(); + List failed_types = new List(); for (int i = 0; i < value_types.Count; i++) { try @@ -1302,9 +1303,10 @@ namespace PascalABCCompiler.NETGenerator SemanticTree.ICommonTypeNode ctn = helper.GetTypeNodeByTypeBuilder(value_types[i]); if (ctn != null) { - if (ctn.is_generic_type_definition) + if (ctn.is_generic_type_definition || ctn.ImplementingInterfaces != null && ctn.ImplementingInterfaces.Count > 0) { bool has_class_contrains = false; + if (ctn.generic_params != null) foreach (var gp in ctn.generic_params) { if (!(gp.base_type is ICommonTypeNode)) @@ -1326,21 +1328,20 @@ namespace PascalABCCompiler.NETGenerator } if (has_class_contrains) continue; + else + { + failed_types.Add(value_types[i]); + continue; + } + } - IAttributeNode[] attrs = ctn.Attributes; - if (attrs.Length > 0 && attrs[0].AttributeType is ICompiledTypeNode && (attrs[0].AttributeType as ICompiledTypeNode).compiled_type == typeof(System.Runtime.InteropServices.StructLayoutAttribute)) - { - throw new PascalABCCompiler.Errors.CommonCompilerError(ex.Message, ctn.Location.document.file_name, ctn.Location.begin_line_num, ctn.Location.begin_column_num); - } - else - throw new PascalABCCompiler.Errors.CommonCompilerError(ex.Message, ctn.Location.document.file_name, ctn.Location.begin_line_num, ctn.Location.begin_column_num); - //throw ex; + throw new PascalABCCompiler.Errors.CommonCompilerError(ex.Message, ctn.Location.document.file_name, ctn.Location.begin_line_num, ctn.Location.begin_column_num); } else throw ex; } } - List failed_types = new List(); + for (int i = 0; i < types.Count; i++) if (!types[i].IsInterface && !closed_types.Contains(types[i])) { @@ -1354,7 +1355,19 @@ namespace PascalABCCompiler.NETGenerator } } for (int i = 0; i < failed_types.Count; i++) - failed_types[i].CreateType(); + try + { + failed_types[i].CreateType(); + } + catch (TypeLoadException ex) + { + SemanticTree.ICommonTypeNode ctn = helper.GetTypeNodeByTypeBuilder(failed_types[i]); + 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); + else + throw ex; + } + } //перевод тела diff --git a/TestSuite/genericrecords4.pas b/TestSuite/genericrecords4.pas new file mode 100644 index 000000000..73bc6a513 --- /dev/null +++ b/TestSuite/genericrecords4.pas @@ -0,0 +1,13 @@ +type + t1 = class end; + i1 = interface end; + + //Ошибка: Could not load type '0.t1' from assembly '0, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. + t2 = record(i1>) + end; + t3 = record(i1>) + end; +begin + var r: t2; + var r2: t3; +end. \ No newline at end of file