fix #1468
This commit is contained in:
parent
8bf5c83d88
commit
e63874ad29
|
|
@ -2951,10 +2951,10 @@ namespace PascalABCCompiler.NETGenerator
|
|||
il.Emit(OpCodes.Stloc, lb);
|
||||
}
|
||||
in_var_init = true;
|
||||
GenerateInitCode(var, il);
|
||||
if (var.type.is_value_type && var.inital_value is ICommonConstructorCall)
|
||||
|
||||
if (!(var.type.is_value_type && var.inital_value is IDefaultOperatorNode))
|
||||
{
|
||||
il.Emit(OpCodes.Stloc, lb);
|
||||
GenerateInitCode(var, il);
|
||||
}
|
||||
in_var_init = false;
|
||||
}
|
||||
|
|
|
|||
24
TestSuite/records16.pas
Normal file
24
TestSuite/records16.pas
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
type
|
||||
t0=class
|
||||
static i := 0;
|
||||
|
||||
constructor :=
|
||||
i += 1;
|
||||
end;
|
||||
r1=record
|
||||
ni := t0.i;
|
||||
end;
|
||||
|
||||
t1=class(t0)
|
||||
|
||||
constructor;
|
||||
begin
|
||||
var a: r1;
|
||||
assert(a.ni = 1);
|
||||
end;
|
||||
|
||||
end;
|
||||
|
||||
begin
|
||||
new t1;
|
||||
end.
|
||||
|
|
@ -2047,6 +2047,18 @@ namespace PascalABCCompiler.TreeConverter
|
|||
|
||||
internal expression_node GetInitalValueForVariable(var_definition_node vdn, expression_node userInitalValue)
|
||||
{
|
||||
if (userInitalValue == null && CurrentStatementList != null && vdn.type.is_value_type && vdn.type is common_type_node)
|
||||
{
|
||||
common_type_node ctn = vdn.type as common_type_node;
|
||||
foreach (var meth in ctn.methods)
|
||||
{
|
||||
if (meth.is_constructor && meth.parameters.Count == 0)
|
||||
{
|
||||
userInitalValue = new common_constructor_call(meth, vdn.location);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (userInitalValue != null)
|
||||
{
|
||||
if (CurrentStatementList != null)
|
||||
|
|
@ -2075,13 +2087,15 @@ namespace PascalABCCompiler.TreeConverter
|
|||
}
|
||||
}
|
||||
}
|
||||
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));
|
||||
if (vdn.type.type_special_kind == SemanticTree.type_special_kind.set_type)
|
||||
{
|
||||
lbvr.type = SystemLibrary.SystemLibInitializer.TypedSetType.sym_info as type_node;
|
||||
}
|
||||
if (vdn.type.is_value_type && userInitalValue is common_constructor_call)
|
||||
{
|
||||
return new default_operator_node(vdn.type, lid);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
if (userInitalValue is constant_node)
|
||||
|
|
|
|||
Loading…
Reference in a new issue