This commit is contained in:
parent
1d34dc7bd8
commit
12cad3fad6
27
TestSuite/constructor2.pas
Normal file
27
TestSuite/constructor2.pas
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
var i: integer;
|
||||
type
|
||||
t1<T> = class
|
||||
|
||||
private static function init_x: integer;
|
||||
begin
|
||||
Inc(i);
|
||||
end;
|
||||
private static x := init_x;
|
||||
|
||||
static constructor;
|
||||
|
||||
end;
|
||||
|
||||
static constructor t1<T>.Create;
|
||||
begin
|
||||
Inc(i);
|
||||
end;
|
||||
|
||||
begin
|
||||
new t1<byte>;
|
||||
assert(i = 2);
|
||||
assert(typeof(t1<byte>).GetConstructors(
|
||||
System.Reflection.BindingFlags.Static or
|
||||
System.Reflection.BindingFlags.NonPublic
|
||||
).Length = 1);
|
||||
end.
|
||||
28
TestSuite/constructor3.pas
Normal file
28
TestSuite/constructor3.pas
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
var i: integer;
|
||||
type
|
||||
t1<T> = class
|
||||
|
||||
private static function init_x: integer;
|
||||
begin
|
||||
Inc(i);
|
||||
end;
|
||||
private static x := init_x;
|
||||
private static y := init_x;
|
||||
|
||||
static constructor;
|
||||
|
||||
end;
|
||||
|
||||
static constructor t1<T>.Create;
|
||||
begin
|
||||
Inc(i);
|
||||
end;
|
||||
|
||||
begin
|
||||
new t1<byte>;
|
||||
assert(i = 3);
|
||||
assert(typeof(t1<byte>).GetConstructors(
|
||||
System.Reflection.BindingFlags.Static or
|
||||
System.Reflection.BindingFlags.NonPublic
|
||||
).Length = 1);
|
||||
end.
|
||||
21
TestSuite/constructor4.pas
Normal file
21
TestSuite/constructor4.pas
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
var i: integer;
|
||||
type
|
||||
t1<T> = class
|
||||
|
||||
private static function init_x: integer;
|
||||
begin
|
||||
Inc(i);
|
||||
end;
|
||||
private static x := init_x;
|
||||
|
||||
end;
|
||||
|
||||
|
||||
begin
|
||||
new t1<byte>;
|
||||
assert(i = 1);
|
||||
assert(typeof(t1<byte>).GetConstructors(
|
||||
System.Reflection.BindingFlags.Static or
|
||||
System.Reflection.BindingFlags.NonPublic
|
||||
).Length = 1);
|
||||
end.
|
||||
27
TestSuite/constructor5.pas
Normal file
27
TestSuite/constructor5.pas
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
var i: integer;
|
||||
type
|
||||
t1 = class
|
||||
|
||||
private static function init_x: integer;
|
||||
begin
|
||||
Inc(i);
|
||||
end;
|
||||
private static x := init_x;
|
||||
|
||||
static constructor;
|
||||
|
||||
end;
|
||||
|
||||
static constructor t1.Create;
|
||||
begin
|
||||
Inc(i);
|
||||
end;
|
||||
|
||||
begin
|
||||
new t1;
|
||||
assert(i = 2);
|
||||
assert(typeof(t1).GetConstructors(
|
||||
System.Reflection.BindingFlags.Static or
|
||||
System.Reflection.BindingFlags.NonPublic
|
||||
).Length = 1);
|
||||
end.
|
||||
|
|
@ -2462,11 +2462,17 @@ namespace PascalABCCompiler.TreeConverter
|
|||
common_method_node stat_ctor;
|
||||
if (sil == null)
|
||||
{
|
||||
stat_ctor = new common_method_node(stat_ctor_name, null, null, generic_def,
|
||||
if (generic_def.static_constr != null)
|
||||
stat_ctor = generic_def.static_constr;
|
||||
else
|
||||
{
|
||||
stat_ctor = new common_method_node(stat_ctor_name, null, null, generic_def,
|
||||
SemanticTree.polymorphic_state.ps_static, SemanticTree.field_access_level.fal_public, null);
|
||||
stat_ctor.is_constructor = true;
|
||||
generic_def.add_name(stat_ctor_name, new SymbolInfo(stat_ctor));
|
||||
generic_def.methods.AddElement(stat_ctor);
|
||||
stat_ctor.is_constructor = true;
|
||||
generic_def.add_name(stat_ctor_name, new SymbolInfo(stat_ctor));
|
||||
generic_def.methods.AddElement(stat_ctor);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -3292,7 +3292,7 @@ namespace PascalABCCompiler.TreeConverter
|
|||
{
|
||||
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
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue