cecilifier icon indicating copy to clipboard operation
cecilifier copied to clipboard

Forward access to types in field declaration assumes field type is external

Open adrianoc opened this issue 3 years ago • 0 comments

using System;

public class A
{
	B b;
}

class B 
{ 	
    A a; 
}

Cecilifying the code above generates the following code for the field definition:

var fld_b_1 = new FieldDefinition("b", FieldAttributes.Private, assembly.MainModule.ImportReference(typeof(B)));
cls_A_0.Fields.Add(fld_b_1);

i.e, it tries to resolve B as typeof(B). Instead the cecilified code should have included the definition of B and use that, i.e, something like:

//Class : B
var cls_B_4 = new TypeDefinition("", "B", TypeAttributes.AnsiClass | TypeAttributes.BeforeFieldInit | TypeAttributes.NotPublic, assembly.MainModule.TypeSystem.Object);
assembly.MainModule.Types.Add(cls_B_4);

var fld_b_1 = new FieldDefinition("b", FieldAttributes.Private, cls_B_4);
cls_A_0.Fields.Add(fld_b_1);

This is related to #188

adrianoc avatar Oct 07 '22 23:10 adrianoc