diff --git a/TestSuite/units/u_staticconstr2.pas b/TestSuite/units/u_staticconstr2.pas new file mode 100644 index 000000000..a6d6e69b2 --- /dev/null +++ b/TestSuite/units/u_staticconstr2.pas @@ -0,0 +1,18 @@ +unit u_staticconstr2; + +type + t1 = partial class + static i: integer; + end; + + t1 = partial class + + static constructor; + begin + Inc(i); + end; + + end; +begin + +end. \ No newline at end of file diff --git a/TestSuite/usesunits/use_staticconstr2.pas b/TestSuite/usesunits/use_staticconstr2.pas new file mode 100644 index 000000000..14b30b5c4 --- /dev/null +++ b/TestSuite/usesunits/use_staticconstr2.pas @@ -0,0 +1,5 @@ +uses u_staticconstr2; +begin + new t1; + assert(t1&.i = 1); +end. \ No newline at end of file diff --git a/TreeConverter/TreeConversion/syntax_tree_visitor.cs b/TreeConverter/TreeConversion/syntax_tree_visitor.cs index dabd71a51..5ac7e67d9 100644 --- a/TreeConverter/TreeConversion/syntax_tree_visitor.cs +++ b/TreeConverter/TreeConversion/syntax_tree_visitor.cs @@ -3262,8 +3262,11 @@ namespace PascalABCCompiler.TreeConverter visit_procedure_header(_constructor); if (context.top_function != null) { - (context.top_function as common_method_node).is_constructor = true; - (context.top_function as common_method_node).cont_type.static_constr = context.top_function as common_method_node; + common_method_node static_constr = context.top_function as common_method_node; + static_constr.is_constructor = true; + if (context.converted_type.IsPartial && context.converted_type.static_constr != null)//remove auto generated static constructor from partial class + context.converted_type.methods.RemoveElement(context.converted_type.static_constr); + static_constr.cont_type.static_constr = context.top_function as common_method_node; } return; }