diff --git a/NETGenerator/NETGenerator.cs b/NETGenerator/NETGenerator.cs index bfe1aa479..fae160da8 100644 --- a/NETGenerator/NETGenerator.cs +++ b/NETGenerator/NETGenerator.cs @@ -4620,16 +4620,6 @@ namespace PascalABCCompiler.NETGenerator FieldBuilder fb = cur_type.DefineField(value.name, type, fattr); helper.AddField(value, fb); MakeAttribute(value); - //временно для поддержки событий - //cur_ti.fields[fb.Name] = fb; - //для массива выделяем память - /*if (ti.is_arr == true) - CreateArray(cur_ti.init_meth.GetILGenerator(), fb, ti, value.inital_value as IArrayConstantNode); - else - if (value.type.is_value_type || value.inital_value is IConstantNode) - AddInitCall(fb, cur_ti.init_meth, ti.init_meth, ti.def_cnstr, value.inital_value as IConstantNode); - GenerateInitCode(value.inital_value,cur_ti.init_meth.GetILGenerator()); - */ if (cur_type.IsValueType && cur_ti.clone_meth != null) { NETGeneratorTools.CloneField(cur_ti.clone_meth as MethodBuilder, fb, ti); @@ -10192,12 +10182,14 @@ namespace PascalABCCompiler.NETGenerator FieldBuilder fb = null; if (value.type is ICompiledTypeNode && (value.type as ICompiledTypeNode).compiled_type.IsEnum) fb = cur_type.DefineField(value.name, TypeFactory.Int32Type, FieldAttributes.Literal | ConvertFALToFieldAttributes(value.field_access_level)); - else + else if (value.constant_value.value != null) fb = cur_type.DefineField(value.name, helper.GetTypeReference(value.type).tp, FieldAttributes.Literal | ConvertFALToFieldAttributes(value.field_access_level)); + else + fb = cur_type.DefineField(value.name, helper.GetTypeReference(value.type).tp, FieldAttributes.Static | ConvertFALToFieldAttributes(value.field_access_level)); if (value.constant_value.value != null) fb.SetConstant(value.constant_value.value); - else - throw new Errors.CompilerInternalError("NetGenerator", new Exception("Invalid constant value in IClassConstantDefinitionNode")); + //else + // throw new Errors.CompilerInternalError("NetGenerator", new Exception("Invalid constant value in IClassConstantDefinitionNode")); } public override void visit(ICompiledStaticMethodCallNodeAsConstant value) diff --git a/TestSuite/classconst2.pas b/TestSuite/classconst2.pas new file mode 100644 index 000000000..dba85065c --- /dev/null +++ b/TestSuite/classconst2.pas @@ -0,0 +1,13 @@ +type + t1 = class + const a = sin(1); + class function test: real; + begin + Result := a; + end; + end; + +begin + assert(abs(t1.test-sin(1)) < 0.000001); + assert(abs(t1.a-sin(1)) < 0.000001); +end. \ No newline at end of file diff --git a/TreeConverter/TreeRealization/constants.cs b/TreeConverter/TreeRealization/constants.cs index a132752a7..9a4b8b51b 100644 --- a/TreeConverter/TreeRealization/constants.cs +++ b/TreeConverter/TreeRealization/constants.cs @@ -48,7 +48,7 @@ namespace PascalABCCompiler.TreeRealization public virtual constant_node get_constant_copy(location loc) { - return null; + return this; } public override type_node type