diff --git a/NETGenerator/NETGenerator.cs b/NETGenerator/NETGenerator.cs index 3de9348f9..2cac39046 100644 --- a/NETGenerator/NETGenerator.cs +++ b/NETGenerator/NETGenerator.cs @@ -4707,9 +4707,12 @@ namespace PascalABCCompiler.NETGenerator { ICommonTypeNode ctn = init_value.type as ICommonTypeNode; IExpressionNode[] FieldValues = init_value.FieldValues; - ICommonClassFieldNode[] Fields = ctn.fields; + List Fields = new List(); + foreach (var field in ctn.fields) + if (field.polymorphic_state != polymorphic_state.ps_static) + Fields.Add(field); - for (int i = 0; i < Fields.Length; i++) + for (int i = 0; i < Fields.Count; i++) { FldInfo field = helper.GetField(Fields[i]); if (FieldValues[i] is IArrayInitializer) @@ -4750,9 +4753,12 @@ namespace PascalABCCompiler.NETGenerator { ICommonTypeNode ctn = init_value.type as ICommonTypeNode; IConstantNode[] FieldValues = init_value.FieldValues; - ICommonClassFieldNode[] Fields = ctn.fields; + List Fields = new List(); + foreach (var field in ctn.fields) + if (field.polymorphic_state != polymorphic_state.ps_static) + Fields.Add(field); - for (int i = 0; i < Fields.Length; i++) + for (int i = 0; i < Fields.Count; i++) { FldInfo field = helper.GetField(Fields[i]); if (FieldValues[i] is IArrayConstantNode) diff --git a/TestSuite/errors/err0539.pas b/TestSuite/errors/err0539.pas new file mode 100644 index 000000000..e0e25e2b0 --- /dev/null +++ b/TestSuite/errors/err0539.pas @@ -0,0 +1,11 @@ +//!Количество полей не совпадает с количеством полей в записи +type + r1 = record + a: byte; + static b: word; + end; + +begin + // Работает, но не должно + var a: r1 := (a: 1; b: 2); +end. \ No newline at end of file diff --git a/TestSuite/recinit3.pas b/TestSuite/recinit3.pas new file mode 100644 index 000000000..956111e24 --- /dev/null +++ b/TestSuite/recinit3.pas @@ -0,0 +1,11 @@ +type + r1 = record + a: byte; + static b: word; + end; + +begin + //Ошибка: Количество полей не совпадает с количеством полей в записи + var a: r1 := (a: 1); + assert(a.a = 1); +end. \ No newline at end of file diff --git a/TreeConverter/TreeConversion/syntax_tree_visitor.cs b/TreeConverter/TreeConversion/syntax_tree_visitor.cs index 69f142444..162e1e9cd 100644 --- a/TreeConverter/TreeConversion/syntax_tree_visitor.cs +++ b/TreeConverter/TreeConversion/syntax_tree_visitor.cs @@ -15597,13 +15597,14 @@ namespace PascalABCCompiler.TreeConverter private record_initializer ConvertRecordInitializer(common_type_node ctn, record_initializer constant) { location loc = constant.location; + var non_static_fields = ctn.fields.TakeWhile(x => !x.IsStatic).ToArray(); if (!ctn.is_value_type) AddError(loc, "RECORD_CONST_NOT_ALLOWED_{0}", ctn.name); - if (ctn.fields.Count != constant.record_const_definition_list.Count) + if (non_static_fields.Length != constant.record_const_definition_list.Count) AddError(loc, "INVALID_RECORD_CONST_FIELD_COUNT"); constant.type = ctn; constant.field_values.Clear(); - for (int i = 0; i < ctn.fields.Count; i++) + for (int i = 0; i < non_static_fields.Length; i++) { class_field cf = ctn.fields[i]; if (cf.name.ToLower() != constant.record_const_definition_list[i].name.name.ToLower())