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

Fix nested type names for properties #584

Merged
merged 1 commit into from
Dec 16, 2024
Merged

Conversation

dpaoliello
Copy link
Contributor

When ClangSharp generates the type name for a property, if the type of the property is a nested type, then it walks from the parent of the current type to the root type and appends the names as it goes. This means that if the nesting is more than one type deep, then the types will be backwards.

For example, given:

typedef union _MY_UNION
{
    long AsArray[2];
    struct {
        long First;
        union {
            struct { long Second; } A;
            struct { long Second; } B;
        }};
    }};
}} MY_UNION;

ClangSharp generates:

public ref _Anonymous_e__Union._Anonymous_e__Struct._B_e__Struct B {
    get {
        fixed (_Anonymous_e__Struct._Anonymous_e__Union* pField = &Anonymous.Anonymous) {
            return ref pField->B;
        }
    }
}

So the type used when pinning the field is correct, but the type for the property itself is incorrect.

The fix is to prepend each type during the walk, then prepend the ref keyword as required.

I also switched the code to use a StringBuilder.

@tannergooding tannergooding merged commit 306222f into dotnet:main Dec 16, 2024
13 checks passed
@dpaoliello dpaoliello deleted the nested branch December 16, 2024 18:41
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

Successfully merging this pull request may close these issues.

2 participants