Beef icon indicating copy to clipboard operation
Beef copied to clipboard

"Only one destructor allowed" error when using EmitTypeBody in a class with an extension destructor

Open disarray2077 opened this issue 4 months ago • 0 comments

The code below fails to compile with the error "Only one destructor allowed".

This error occurs only if EmitTypeBody emits any code and both the extension and the extension's base class have a destructor.

class X<T>
{
    ~this()
    {
    }

    [OnCompile(.TypeInit), Comptime]
    static void Init()
    {
        String emitStr = """
            public void Test() {}
            """;

        Compiler.EmitTypeBody(typeof(Self), emitStr);
    }
}

extension X<T> where T : IDisposable
{
    ~this()
    {
    }
}

class Program
{
    public static int Main()
    {
        X<String> a = scope .();
    }
}

Tested with: 9c9d29d493b06328d64b48edcb1b07d57406c2a0

disarray2077 avatar Aug 20 '25 20:08 disarray2077