fix #1166
This commit is contained in:
parent
f3ee283ea8
commit
8bf5c83d88
|
|
@ -2952,6 +2952,10 @@ namespace PascalABCCompiler.NETGenerator
|
||||||
}
|
}
|
||||||
in_var_init = true;
|
in_var_init = true;
|
||||||
GenerateInitCode(var, il);
|
GenerateInitCode(var, il);
|
||||||
|
if (var.type.is_value_type && var.inital_value is ICommonConstructorCall)
|
||||||
|
{
|
||||||
|
il.Emit(OpCodes.Stloc, lb);
|
||||||
|
}
|
||||||
in_var_init = false;
|
in_var_init = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
24
TestSuite/records15.pas
Normal file
24
TestSuite/records15.pas
Normal file
|
|
@ -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.
|
||||||
|
|
@ -2055,26 +2055,28 @@ namespace PascalABCCompiler.TreeConverter
|
||||||
location lid = ((local_block_variable)vdn).loc;
|
location lid = ((local_block_variable)vdn).loc;
|
||||||
local_block_variable_reference lbvr = new local_block_variable_reference((local_block_variable)vdn, lid);
|
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)
|
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 = syntax_tree_visitor.get_init_call_for_set_as_constr(vdn, userInitalValue);
|
||||||
//userInitalValue.type = SystemLibrary.SystemLibInitializer.TypedSetType.sym_info as type_node;
|
//userInitalValue.type = SystemLibrary.SystemLibInitializer.TypedSetType.sym_info as type_node;
|
||||||
}
|
}
|
||||||
else if (vdn.type.type_special_kind == SemanticTree.type_special_kind.short_string)
|
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));
|
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)
|
else if (userInitalValue is array_initializer)
|
||||||
{
|
{
|
||||||
array_initializer arr = userInitalValue as array_initializer;
|
array_initializer arr = userInitalValue as array_initializer;
|
||||||
if (vdn.type.element_type.type_special_kind == SemanticTree.type_special_kind.short_string)
|
if (vdn.type.element_type.type_special_kind == SemanticTree.type_special_kind.short_string)
|
||||||
{
|
{
|
||||||
for (int i=0; i<arr.element_values.Count; i++)
|
for (int i = 0; i < arr.element_values.Count; i++)
|
||||||
{
|
{
|
||||||
//arr.element_values[i] = syntax_tree_visitor.find_operator(compiler_string_consts.assign_name, varref2, arr.element_values[i], null);
|
//arr.element_values[i] = syntax_tree_visitor.find_operator(compiler_string_consts.assign_name, varref2, arr.element_values[i], null);
|
||||||
arr.element_values[i] = convertion_data_and_alghoritms.create_simple_function_call(SystemLibrary.SystemLibInitializer.ClipShortStringProcedure.sym_info as function_node,null,convertion_data_and_alghoritms.convert_type(arr.element_values[i],SystemLibrary.SystemLibrary.string_type),new int_const_node((vdn.type.element_type as short_string_type_node).Length,null));
|
arr.element_values[i] = convertion_data_and_alghoritms.create_simple_function_call(SystemLibrary.SystemLibInitializer.ClipShortStringProcedure.sym_info as function_node, null, convertion_data_and_alghoritms.convert_type(arr.element_values[i], SystemLibrary.SystemLibrary.string_type), new int_const_node((vdn.type.element_type as short_string_type_node).Length, null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (vdn.type.is_value_type && userInitalValue is common_constructor_call)
|
||||||
|
return userInitalValue;
|
||||||
CurrentStatementList.statements.AddElement(syntax_tree_visitor.find_operator(compiler_string_consts.assign_name, lbvr, userInitalValue, lid));
|
CurrentStatementList.statements.AddElement(syntax_tree_visitor.find_operator(compiler_string_consts.assign_name, lbvr, userInitalValue, lid));
|
||||||
if (vdn.type.type_special_kind == SemanticTree.type_special_kind.set_type)
|
if (vdn.type.type_special_kind == SemanticTree.type_special_kind.set_type)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue