This commit is contained in:
Ivan Bondarev 2024-06-09 19:35:35 +02:00
parent e5f60689cd
commit 8bddc9e62a
4 changed files with 35 additions and 6 deletions

View file

@ -4707,9 +4707,12 @@ namespace PascalABCCompiler.NETGenerator
{
ICommonTypeNode ctn = init_value.type as ICommonTypeNode;
IExpressionNode[] FieldValues = init_value.FieldValues;
ICommonClassFieldNode[] Fields = ctn.fields;
List<ICommonClassFieldNode> Fields = new List<ICommonClassFieldNode>();
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<ICommonClassFieldNode> Fields = new List<ICommonClassFieldNode>();
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)

View file

@ -0,0 +1,11 @@
//!Количество полей не совпадает с количеством полей в записи
type
r1 = record
a: byte;
static b: word;
end;
begin
// Работает, но не должно
var a: r1 := (a: 1; b: 2);
end.

11
TestSuite/recinit3.pas Normal file
View file

@ -0,0 +1,11 @@
type
r1 = record
a: byte;
static b: word;
end;
begin
//Ошибка: Количество полей не совпадает с количеством полей в записи
var a: r1 := (a: 1);
assert(a.a = 1);
end.

View file

@ -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())