This commit is contained in:
parent
ec18666893
commit
c25e2e401e
|
|
@ -5029,6 +5029,11 @@ namespace PascalABCCompiler.NETGenerator
|
|||
GenerateInitCodeForField(ccf);
|
||||
else
|
||||
GenerateInitCodeForStaticField(ccf);
|
||||
foreach (IClassConstantDefinitionNode cnst in ctn.constants)
|
||||
if (cnst.constant_value is IArrayConstantNode)
|
||||
{
|
||||
GenerateInitCodeForClassConstant(cnst);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -5070,6 +5075,16 @@ namespace PascalABCCompiler.NETGenerator
|
|||
in_var_init = false;
|
||||
}
|
||||
|
||||
internal void GenerateInitCodeForClassConstant(SemanticTree.IClassConstantDefinitionNode value)
|
||||
{
|
||||
TypeInfo ti = helper.GetTypeReference(value.type), cur_ti = helper.GetTypeReference(value.comperehensive_type);
|
||||
FieldBuilder fb = helper.GetConstant(value).fb as FieldBuilder;
|
||||
|
||||
if (value.constant_value is IArrayConstantNode)
|
||||
CreateArrayForClassField(cur_ti.static_cnstr.GetILGenerator(), fb, ti, value.constant_value as IArrayConstantNode, value.type);
|
||||
|
||||
}
|
||||
|
||||
internal void GenerateInitCodeForField(SemanticTree.ICommonClassFieldNode value)
|
||||
{
|
||||
TypeInfo ti = helper.GetTypeReference(value.type), cur_ti = helper.GetTypeReference(value.comperehensive_type);
|
||||
|
|
@ -11007,6 +11022,8 @@ namespace PascalABCCompiler.NETGenerator
|
|||
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
|
||||
helper.AddConstant(value, fb);
|
||||
//else
|
||||
// throw new Errors.CompilerInternalError("NetGenerator", new Exception("Invalid constant value in IClassConstantDefinitionNode"));
|
||||
}
|
||||
|
|
|
|||
14
TestSuite/classconst4.pas
Normal file
14
TestSuite/classconst4.pas
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
|
||||
type
|
||||
TArrStr = array of string;
|
||||
t1 = class
|
||||
|
||||
public const arr: array of string = ('abc', 'def');
|
||||
|
||||
end;
|
||||
|
||||
begin
|
||||
var arr := TArrStr(typeof(t1).GetField('arr').GetValue(nil));
|
||||
assert(arr[0] = 'abc');
|
||||
assert(arr[1] = 'def');
|
||||
end.
|
||||
Loading…
Reference in a new issue