This commit is contained in:
Ivan Bondarev 2024-07-07 11:17:26 +02:00
parent f528ee0ad8
commit af2bc0fda8
4 changed files with 91 additions and 69 deletions

View file

@ -3885,7 +3885,11 @@ namespace PascalABCCompiler.NETGenerator
if (ti != null && ti.tp.IsValueType && !TypeFactory.IsStandType(ti.tp) && (helper.IsConstructedGenericType(ti.tp) || ti.tp.IsGenericType || !ti.tp.IsEnum))
if (!(ti.tp is EnumBuilder))
il.Emit(OpCodes.Ldelema, ti.tp);
if (_arr_type.is_nullable_type && exprs[i] is INullConstantNode)
{
il.Emit(OpCodes.Initobj, helper.GetTypeReference(_arr_type).tp);
continue;
}
this.il = il;
exprs[i].visit(this);
bool box = EmitBox(exprs[i], arr_type.GetElementType());
@ -4603,12 +4607,14 @@ namespace PascalABCCompiler.NETGenerator
{
if (!(ti.tp is EnumBuilder))
il.Emit(OpCodes.Ldelema, ti.tp);
}
else
if (ti != null && ti.assign_meth != null && lb.LocalType.GetElementType() != TypeFactory.ObjectType)
il.Emit(OpCodes.Ldelem_Ref);
this.il = il;
ElementValues[i].visit(this);
if (ti != null && ti.assign_meth != null && lb.LocalType.GetElementType() != TypeFactory.ObjectType)
{

4
TestSuite/nullable15.pas Normal file
View file

@ -0,0 +1,4 @@
begin
var a := new System.Nullable<integer>[](nil);
assert(a[0] = nil);
end.

4
TestSuite/nullable16.pas Normal file
View file

@ -0,0 +1,4 @@
var a := new System.Nullable<integer>[](nil);
begin
assert(a[0] = nil);
end.

8
TestSuite/nullable17.pas Normal file
View file

@ -0,0 +1,8 @@
procedure test(params a: array of System.Nullable<integer>);
begin
assert(a[0] = nil);
assert(a[1] = 1);
end;
begin
test(nil, 1);
end.