From 7f2776dbe38dab611d77375d73c0ce3ecfbcda7f Mon Sep 17 00:00:00 2001 From: Ivan Bondarev Date: Thu, 16 Jun 2022 13:28:21 +0200 Subject: [PATCH] fix #2667 --- NETGenerator/NETGenerator.cs | 22 +++++++++++++--------- TestSuite/classfield3.pas | 14 ++++++++++++++ TestSuite/classfield4.pas | 14 ++++++++++++++ 3 files changed, 41 insertions(+), 9 deletions(-) create mode 100644 TestSuite/classfield3.pas create mode 100644 TestSuite/classfield4.pas diff --git a/NETGenerator/NETGenerator.cs b/NETGenerator/NETGenerator.cs index 3139817de..239342655 100644 --- a/NETGenerator/NETGenerator.cs +++ b/NETGenerator/NETGenerator.cs @@ -835,15 +835,7 @@ namespace PascalABCCompiler.NETGenerator ConvertGenericFunctionInstance(igfi); } - for (int iii = 0; iii < cnns.Length; iii++) - { - if (save_debug_info) doc = sym_docs[cnns[iii].Location == null ? SourceFileName : cnns[iii].Location.document.file_name]; - cur_type = NamespacesTypes[cnns[iii]]; - cur_unit_type = NamespacesTypes[cnns[iii]]; - //генерим инциализацию для полей - foreach (SemanticTree.ICommonTypeNode ctn in cnns[iii].types) - GenerateInitCodeForFields(ctn); - } + ConstructorBuilder unit_cci = null; @@ -899,6 +891,16 @@ namespace PascalABCCompiler.NETGenerator cur_unit = tmp_unit_name; } + for (int iii = 0; iii < cnns.Length; iii++) + { + if (save_debug_info) doc = sym_docs[cnns[iii].Location == null ? SourceFileName : cnns[iii].Location.document.file_name]; + cur_type = NamespacesTypes[cnns[iii]]; + cur_unit_type = NamespacesTypes[cnns[iii]]; + //генерим инциализацию для полей + foreach (SemanticTree.ICommonTypeNode ctn in cnns[iii].types) + GenerateInitCodeForFields(ctn); + } + if (p.InitializationCode != null) { tmp_il = il; @@ -4656,6 +4658,8 @@ namespace PascalABCCompiler.NETGenerator { //Console.WriteLine(is_in_unit); //if (is_in_unit && helper.IsUsed(var)==false) return; + if (helper.GetVariable(var) != null) + return; TypeInfo ti = helper.GetTypeReference(var.type); FieldBuilder fb = cur_type.DefineField(var.name, ti.tp, FieldAttributes.Public | FieldAttributes.Static); helper.AddGlobalVariable(var, fb); diff --git a/TestSuite/classfield3.pas b/TestSuite/classfield3.pas new file mode 100644 index 000000000..2cf65fb79 --- /dev/null +++ b/TestSuite/classfield3.pas @@ -0,0 +1,14 @@ +var x := 1; + +type + t1 = static class + static o := x; + end; + +begin + assert(x = 1); + x := 5; + assert(x = 5); + assert(t1.o = 5); + assert(x = 5); +end. \ No newline at end of file diff --git a/TestSuite/classfield4.pas b/TestSuite/classfield4.pas new file mode 100644 index 000000000..8cf2c3bfb --- /dev/null +++ b/TestSuite/classfield4.pas @@ -0,0 +1,14 @@ +type + t1 = static class + static o := 1; + end; + +var x := t1.o; + +begin + assert(x = 1); + x := 5; + assert(x = 5); + assert(t1.o = 1); + assert(x = 5); +end. \ No newline at end of file