Fix incorrect expectedCursorKind for UsingEnumDecl#742
Merged
tannergooding merged 2 commits intoJul 13, 2026
Merged
Conversation
libClang surfaces a `using enum` declaration with `cursor.kind == CXCursor_EnumDecl`, so passing `CXCursor_UnexposedDecl` to the base `Cursor` ctor caused an `ArgumentOutOfRangeException` when walking any decl tree that contained a `using enum`. The deeper `EnumDecl` accessor issue (`Handle.Definition` surfaces as an empty `CXCursor_OverloadedDeclRef`) is not resolvable against the prebuilt native lib and needs a native `libClangSharp` shim wrapping `UsingEnumDecl::getEnumDecl()`; that is left for a follow-up and documented in the code. Fixes dotnet#633 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
`Handle.Definition` surfaces as an empty `CXCursor_OverloadedDeclRef` for a `using enum`, so the `EnumDecl` accessor could not resolve the referenced enum. Add a native `clangsharp_Cursor_getUsingEnumDeclEnumDecl` shim wrapping clang's `UsingEnumDecl::getEnumDecl()`, expose the matching interop, and route `EnumDeclFactory` through it instead of `Handle.Definition`. The native shim cannot be built or tested in this environment; the pinned 21.1 prebuilt `libClangSharp` package lacks the new entry point, so the added `UsingEnumDeclEnumDeclTest` is guarded by `SkipUntilNativeRebuild` and stays skipped until the native lib is rebuilt for a newer libClang. Validating this change requires that native rebuild. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #633.
UsingEnumDeclpassedCXCursor_UnexposedDeclas its expected cursor kind, but libClang surfaces ausing enumdeclaration withcursor.kind == CXCursor_EnumDecl(itsDeclKindisCX_DeclKind_UsingEnum). The baseCursorctor kind-check therefore threwArgumentOutOfRangeExceptionwhen walking any decl tree that contained ausing enum. Fixed by expectingCXCursor_EnumDecl.Also resolves
UsingEnumDecl.EnumDecl.Handle.Definitionsurfaces as an emptyCXCursor_OverloadedDeclReffor ausing enum, so the accessor could not resolve the referenced enum. Added a nativeclangsharp_Cursor_getUsingEnumDeclEnumDeclshim wrapping clang'sUsingEnumDecl::getEnumDecl(), exposed the matching interop, and routedEnumDeclFactorythrough it.The two changes are split into separate commits:
Fix incorrect expectedCursorKind for UsingEnumDecl— managed-only, fully verified here (unguarded construction test).Resolve UsingEnumDecl.EnumDecl via a native getEnumDecl shim— the native shim + interop. The pinned 21.1 prebuiltlibClangSharppackage predates the new entry point, so itsUsingEnumDeclEnumDeclTestis guarded bySkipUntilNativeRebuildand stays skipped until the native lib is rebuilt for a newer libClang. This commit needs a nativelibClangSharprebuild to validate.Tests:
dotnet test tests/ClangSharp.UnitTests-> 56 passed, 3 skipped (2 pre-existing template-arg + the new guarded accessor test), 0 failed. Build is clean (0 warnings). No generator/golden churn.