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

Generating nested types are not sufficiently qualified #579

Open
Helco opened this issue Nov 18, 2024 · 1 comment
Open

Generating nested types are not sufficiently qualified #579

Helco opened this issue Nov 18, 2024 · 1 comment

Comments

@Helco
Copy link

Helco commented Nov 18, 2024

When using nested types as method parameters, the type is not fully declared leading to syntax errors in the C# code. A reproduction is as follows:

struct A
{
    struct Inner {};
};
struct B
{
    virtual void Method(A::Inner& inner);
};
USER@PC MINGW64 /c/Develop/prv/
$ ClangSharpPInvokeGenerator.exe --file bug/bug.h --output bug/output -n Bug
Processing 'bug/bug.h'

USER@PC MINGW64 /c/Develop/prv/
$ ClangSharpPInvokeGenerator --version
ClangSharp P/Invoke Binding Generator version 18.1.3
  clang version 18.1.3 (https://github.com/llvm/llvm-project c13b7485b87909fcf739f62cfa382b55407433c0)
  clangsharp version 18.1.3

leads to

namespace Bug
{
    public partial struct A
    {

        public partial struct Inner
        {
        }
    }
    public unsafe partial struct B
    {
        public void** lpVtbl;

        public void Method([NativeTypeName("A::Inner &")] Inner* inner)
        {
            ((delegate* unmanaged[Thiscall]<B*, Inner*, void>)(lpVtbl[0]))((B*)Unsafe.AsPointer(ref this), inner);
        }
    }
}

where Method should be declared as public void Method([NativeTypeName("A::Inner &")] A.Inner* inner).

A possible workaround is to use --remap A::Inner=AInner and to add an own C# file with the contents global using AInner = Bug.A.AInner;

@tannergooding
Copy link
Member

This shouldn't be difficult to fix, there's likely just a context being passed down incorrectly somewhere.

C++ bindings in general, especially as you get into more complex type definitions, are tricky and Clang doesn't always consistently surface the AST information in a way that makes it trivial to resolve.

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

2 participants