Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty extern constructor fails to compile #2091

Open
Grimelios opened this issue Jan 13, 2025 · 0 comments
Open

Empty extern constructor fails to compile #2091

Grimelios opened this issue Jan 13, 2025 · 0 comments

Comments

@Grimelios
Copy link

Grimelios commented Jan 13, 2025

I'm running nightly 01/10/2025. Consider project A (a console application) that depends on project B (a library). First, here's project B (the library):

using System;

namespace B
{
    static
    {
        public static void Run()
        {
            MyClass @class = new .();
        }
    }

    public class MyClass
    {
        public extern this();
    }
}

Second, here's project A (the application):

using B;
using System;

namespace A
{
    static
    {
        public static void Main()
        {
            B.Run();
        }
    }
}

namespace B
{
    public extension MyClass
    {
        public override this()
        {
        }
    }
}

As shown, project B has a class MyClass with an empty extern constructor. Project A extends MyClass to provide an implementation for that constructor, but the project fails to compile (with error LNK2019: unresolved external symbol).

Adding a parameter to the constructor results in a successful compilation:

public class MyClass
{
    // Other relevant code is updated to also account for this parameter.
    public extern this(int32 value);
}

Interestingly, adding MyClass destructors to both projects also results in a successful compilation, even with the constructor remaining empty. Adding a destructor to only one project doesn't cut it.

// In project A...
public extension MyClass
{
    public override this()
    {
    }

    public ~this()
    {
    }
}

// In project B...
public class MyClass
{
    public extern this();

    public ~this()
    {
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant