Skip to content

fix(csharp): explicit interface implementations are public, not private - #2302

Open
zichen0116 wants to merge 1 commit into
colbymchenry:mainfrom
zichen0116:fix/csharp-explicit-interface-visibility
Open

zichen0116 wants to merge 1 commit into
colbymchenry:mainfrom
zichen0116:fix/csharp-explicit-interface-visibility

Conversation

@zichen0116

Copy link
Copy Markdown
Contributor

Closes #2164

Problem

Since #1745, cross-file resolution declines candidates whose visibility is
private (they are treated as file-local) — and the C# extractor defaulted
every modifier-less member to private. That default is wrong for explicit
interface implementations: void IOrderService.CancelOrder(int id) cannot
carry an access modifier in C# (CS0106), but it is reachable through the
interface, so it must not be treated as file-local.

The two other cases from #2164 (interface members, top-level types) were
already fixed by #2220; this covers the remaining one.

Fix

In the C# getVisibility, return public when the member node carries an
explicit_interface_specifier child (methods, properties, indexers, events —
all share this node shape):

// An explicit interface implementation (`void IFoo.Bar()`) cannot carry
// an access modifier; it is reachable through the interface, so it is
// public even though its class body declares it (#2164).
if (child?.type === 'explicit_interface_specifier') return 'public';

Verification

New regression test __tests__/csharp-interface-visibility.test.ts (real
indexing through the full CodeGraph pipeline):

Also ran: all 5 C# suites (11 tests) pass, __tests__/extraction.test.ts
(691 tests) passes, tsc --noEmit clean. Added a CHANGELOG.md entry under
[Unreleased] → ### Fixes per the repo's changelog rules.

This branch has not been deployed

No deployments
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.

C#: calls through an interface are no longer resolved since 1.6.1 (interface members extracted as private)

1 participant