From 8bf5c83d8877cab240e06cf4a08acfcd7a370d30 Mon Sep 17 00:00:00 2001 From: Ivan Bondarev Date: Wed, 30 Dec 2020 11:10:18 +0100 Subject: [PATCH] fix #1166 --- NETGenerator/NETGenerator.cs | 4 +++ TestSuite/records15.pas | 24 ++++++++++++++ .../TreeConversion/compilation_context.cs | 32 ++++++++++--------- 3 files changed, 45 insertions(+), 15 deletions(-) create mode 100644 TestSuite/records15.pas diff --git a/NETGenerator/NETGenerator.cs b/NETGenerator/NETGenerator.cs index 31a77ffbe..fb7ab9a9e 100644 --- a/NETGenerator/NETGenerator.cs +++ b/NETGenerator/NETGenerator.cs @@ -2952,6 +2952,10 @@ namespace PascalABCCompiler.NETGenerator } in_var_init = true; GenerateInitCode(var, il); + if (var.type.is_value_type && var.inital_value is ICommonConstructorCall) + { + il.Emit(OpCodes.Stloc, lb); + } in_var_init = false; } diff --git a/TestSuite/records15.pas b/TestSuite/records15.pas new file mode 100644 index 000000000..fce925cce --- /dev/null +++ b/TestSuite/records15.pas @@ -0,0 +1,24 @@ +var i: integer; + +type + r1 = record + public function InitI1:integer; + begin + Result := 1; + Inc(i); + end; + + public i1: integer := InitI1; + end; + +procedure test; +var a := new r1; +begin + +end; +begin + var a := new r1; + assert(i = 1); + test; + assert(i = 2); +end. \ No newline at end of file diff --git a/TreeConverter/TreeConversion/compilation_context.cs b/TreeConverter/TreeConversion/compilation_context.cs index 6fae15e49..a9f65ad3f 100644 --- a/TreeConverter/TreeConversion/compilation_context.cs +++ b/TreeConverter/TreeConversion/compilation_context.cs @@ -2055,26 +2055,28 @@ namespace PascalABCCompiler.TreeConverter location lid = ((local_block_variable)vdn).loc; local_block_variable_reference lbvr = new local_block_variable_reference((local_block_variable)vdn, lid); if (vdn.type.type_special_kind == SemanticTree.type_special_kind.set_type) - { - userInitalValue = syntax_tree_visitor.get_init_call_for_set_as_constr(vdn,userInitalValue); - //userInitalValue.type = SystemLibrary.SystemLibInitializer.TypedSetType.sym_info as type_node; - } + { + userInitalValue = syntax_tree_visitor.get_init_call_for_set_as_constr(vdn, userInitalValue); + //userInitalValue.type = SystemLibrary.SystemLibInitializer.TypedSetType.sym_info as type_node; + } else if (vdn.type.type_special_kind == SemanticTree.type_special_kind.short_string) { userInitalValue = convertion_data_and_alghoritms.create_simple_function_call(SystemLibrary.SystemLibInitializer.ClipShortStringProcedure.sym_info as function_node, null, convertion_data_and_alghoritms.convert_type(userInitalValue, SystemLibrary.SystemLibrary.string_type), new int_const_node((vdn.type as short_string_type_node).Length, null)); } else if (userInitalValue is array_initializer) - { - array_initializer arr = userInitalValue as array_initializer; - if (vdn.type.element_type.type_special_kind == SemanticTree.type_special_kind.short_string) - { - for (int i=0; i