Skip to content

Fix incorrect expectedCursorKind for UsingEnumDecl#742

Merged
tannergooding merged 2 commits into
dotnet:mainfrom
tannergooding:tannergooding-fix-usingenumdecl-cursorkind
Jul 13, 2026
Merged

Fix incorrect expectedCursorKind for UsingEnumDecl#742
tannergooding merged 2 commits into
dotnet:mainfrom
tannergooding:tannergooding-fix-usingenumdecl-cursorkind

Conversation

@tannergooding

Copy link
Copy Markdown
Member

Fixes #633.

UsingEnumDecl passed CXCursor_UnexposedDecl as its expected cursor kind, but libClang surfaces a using enum declaration with cursor.kind == CXCursor_EnumDecl (its DeclKind is CX_DeclKind_UsingEnum). The base Cursor ctor kind-check therefore threw ArgumentOutOfRangeException when walking any decl tree that contained a using enum. Fixed by expecting CXCursor_EnumDecl.


Also resolves UsingEnumDecl.EnumDecl. Handle.Definition surfaces as an empty CXCursor_OverloadedDeclRef for a using enum, so the accessor could not resolve the referenced enum. Added a native clangsharp_Cursor_getUsingEnumDeclEnumDecl shim wrapping clang's UsingEnumDecl::getEnumDecl(), exposed the matching interop, and routed EnumDeclFactory through it.

The two changes are split into separate commits:

  • 9fad045 Fix incorrect expectedCursorKind for UsingEnumDecl — managed-only, fully verified here (unguarded construction test).
  • 0bfb581 Resolve UsingEnumDecl.EnumDecl via a native getEnumDecl shim — the native shim + interop. The pinned 21.1 prebuilt libClangSharp package predates the new entry point, so its UsingEnumDeclEnumDeclTest is guarded by SkipUntilNativeRebuild and stays skipped until the native lib is rebuilt for a newer libClang. This commit needs a native libClangSharp rebuild 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.

tannergooding and others added 2 commits July 13, 2026 01:13
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>
@tannergooding tannergooding merged commit d0375cf into dotnet:main Jul 13, 2026
14 checks passed
@tannergooding tannergooding deleted the tannergooding-fix-usingenumdecl-cursorkind branch July 13, 2026 15:11
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.

UsingEnumDecl's expectedCursorKind

1 participant