This commit is contained in:
Ivan Bondarev 2022-06-16 13:28:21 +02:00
parent 3d9be59793
commit 7f2776dbe3
3 changed files with 41 additions and 9 deletions

View file

@ -835,15 +835,7 @@ namespace PascalABCCompiler.NETGenerator
ConvertGenericFunctionInstance(igfi);
}
for (int iii = 0; iii < cnns.Length; iii++)
{
if (save_debug_info) doc = sym_docs[cnns[iii].Location == null ? SourceFileName : cnns[iii].Location.document.file_name];
cur_type = NamespacesTypes[cnns[iii]];
cur_unit_type = NamespacesTypes[cnns[iii]];
//генерим инциализацию для полей
foreach (SemanticTree.ICommonTypeNode ctn in cnns[iii].types)
GenerateInitCodeForFields(ctn);
}
ConstructorBuilder unit_cci = null;
@ -899,6 +891,16 @@ namespace PascalABCCompiler.NETGenerator
cur_unit = tmp_unit_name;
}
for (int iii = 0; iii < cnns.Length; iii++)
{
if (save_debug_info) doc = sym_docs[cnns[iii].Location == null ? SourceFileName : cnns[iii].Location.document.file_name];
cur_type = NamespacesTypes[cnns[iii]];
cur_unit_type = NamespacesTypes[cnns[iii]];
//генерим инциализацию для полей
foreach (SemanticTree.ICommonTypeNode ctn in cnns[iii].types)
GenerateInitCodeForFields(ctn);
}
if (p.InitializationCode != null)
{
tmp_il = il;
@ -4656,6 +4658,8 @@ namespace PascalABCCompiler.NETGenerator
{
//Console.WriteLine(is_in_unit);
//if (is_in_unit && helper.IsUsed(var)==false) return;
if (helper.GetVariable(var) != null)
return;
TypeInfo ti = helper.GetTypeReference(var.type);
FieldBuilder fb = cur_type.DefineField(var.name, ti.tp, FieldAttributes.Public | FieldAttributes.Static);
helper.AddGlobalVariable(var, fb);

14
TestSuite/classfield3.pas Normal file
View file

@ -0,0 +1,14 @@
var x := 1;
type
t1 = static class
static o := x;
end;
begin
assert(x = 1);
x := 5;
assert(x = 5);
assert(t1.o = 5);
assert(x = 5);
end.

14
TestSuite/classfield4.pas Normal file
View file

@ -0,0 +1,14 @@
type
t1 = static class
static o := 1;
end;
var x := t1.o;
begin
assert(x = 1);
x := 5;
assert(x = 5);
assert(t1.o = 1);
assert(x = 5);
end.