cecilifier
cecilifier copied to clipboard
Record declaration generates code that references the record type through `typeof()` as opposed to the generated `TypeReference`
using System;
class TestStruct
{
static void Main()
{
R r = new R(1);
}
}
record R(int Value);
Produces (edited for readability) :
//Class : R
var cls_R_3 = new TypeDefinition("", "R", TypeAttributes.AnsiClass | TypeAttributes.BeforeFieldInit | TypeAttributes.NotPublic, assembly.MainModule.TypeSystem.Object);
var t = assembly.MainModule.ImportReference(typeof(R)); // ** THIS IS WRONG **
cls_R_3.Interfaces.Add(new InterfaceImplementation(assembly.MainModule.ImportReference(typeof(System.IEquatable<>)).MakeGenericInstanceType(t)));
instead of:
//Class : R
var cls_R_3 = new TypeDefinition("", "R", TypeAttributes.AnsiClass | TypeAttributes.BeforeFieldInit | TypeAttributes.NotPublic, assembly.MainModule.TypeSystem.Object);
var t = cls_R_3; // ** the type reference to 'R' should have been used, i.e, cls_R_3 **
cls_R_3.Interfaces.Add(new InterfaceImplementation(assembly.MainModule.ImportReference(typeof(System.IEquatable<>)).MakeGenericInstanceType(t)));
[!NOTE] It looks like we are not explicitly visiting record nodes in the syntax three. The behaviour in this issue may be a side effect of that Lets add a test with a single record declaration:
record R(int Value);
actually found out that most features of records are not supported at all (the ones that may work are just by accident)
Added a task to implement support correctly.