Skip to content

Struct with a field - pointer to a struct of the same type, when passed by value: error CS0523 in the generated code #1216

Open
@AleXr64

Description

@AleXr64
Used headers
#define CS_VALUE_TYPE
struct CS_VALUE_TYPE Foo
{
	Foo* Bar;
};
Stack trace or incompilable generated code
    public unsafe partial struct Foo
    {
        [StructLayout(LayoutKind.Explicit, Size = 4)]
        public partial struct __Internal
        {
            [FieldOffset(0)]
            internal global::System.IntPtr Bar;

            [SuppressUnmanagedCodeSecurity]
            [DllImport("__Internal", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall,
                EntryPoint="??0Foo@@QAE@ABU0@@Z")]
            internal static extern global::System.IntPtr cctor(global::System.IntPtr __instance, global::System.IntPtr _0);
        }

        private Foo.__Internal __instance;
        internal Foo.__Internal __Instance { get { return __instance; } }

        internal static global::Buggy.Foo __CreateInstance(global::System.IntPtr native, bool skipVTables = false)
        {
            return new global::Buggy.Foo(native.ToPointer(), skipVTables);
        }

        internal static global::Buggy.Foo __CreateInstance(global::Buggy.Foo.__Internal native, bool skipVTables = false)
        {
            return new global::Buggy.Foo(native, skipVTables);
        }

        private Foo(global::Buggy.Foo.__Internal native, bool skipVTables = false)
            : this()
        {
            __instance = native;
        }

        private Foo(void* native, bool skipVTables = false) : this()
        {
            __instance = *(global::Buggy.Foo.__Internal*) native;
        }

        public Foo(global::Buggy.Foo _0)
            : this()
        {
            var ____arg0 = _0.__Instance;
            var __arg0 = new global::System.IntPtr(&____arg0);
            fixed (__Internal* __instancePtr = &__instance)
            {
                __Internal.cctor(new global::System.IntPtr(__instancePtr), __arg0);
            }
        }

        public global::Buggy.Foo Bar; //compiler error CS0523
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions