This commit is contained in:
Ivan Bondarev 2024-03-29 13:39:35 +01:00
parent 1d82d488a4
commit cbaff8cfd0
2 changed files with 65 additions and 28 deletions

View file

@ -10292,12 +10292,23 @@ namespace PascalABCCompiler.NETGenerator
if (temp_is_dot_expr)
{
if (elem_type.IsGenericParameter)
{
if (value.array.type.element_type.is_generic_parameter && value.array.type.element_type.base_type != null && value.array.type.element_type.base_type.is_class && value.array.type.element_type.base_type.base_type != null)
{
if (indices == null)
il.Emit(OpCodes.Ldelem_Ref);
else
il.Emit(OpCodes.Call, get_meth);
}
else
{
if (indices == null)
il.Emit(OpCodes.Ldelema, elem_type);
else
il.Emit(OpCodes.Call, addr_meth);
}
}
else if (elem_type.IsValueType == true)
{
if (indices == null)

26
TestSuite/generics75.pas Normal file
View file

@ -0,0 +1,26 @@
var s: string;
type
c1<TSelf> = class
where TSelf: c1<TSelf>;
x: string := 'abc';
static a := new TSelf[1];
static procedure p1;
begin
assert((a[0] as c1<TSelf>).x.Length = 3); // 3
s := a[0].x; // nil
a[0].x := 'abc';
assert((a[0] as c1<TSelf>).x.Length = 3); // 0
end;
end;
c2 = class(c1<c2>) end;
begin
c2.a[0] := new c2;
c2.p1;
assert(c2.a[0].x.Length = 3); // 0
assert(s = 'abc');
end.