Skip to content

Search an interface's ancestors breadth-first by inheritance distance [patch] - #180

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/178-interface-search-by-distance
Nov 4, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/178-interface-search-by-distance

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #178

What was wrong

SearchLevels grouped an interface's inherited interfaces by i.GetInterfaces().Length, which is how deep each interface's own ancestry runs, not how far it is from type. A direct parent with no bases ended up in the last group. So IDerived : IBase, IX returned IRoot.Foo(int), two levels up, instead of IX.Foo(). Adding a base to IX changed the result.

What changed

  • Interface levels are now built breadth-first. Level 1 holds type's direct interfaces: the members of GetInterfaces() that no other member of that set inherits. Each later level holds the direct bases of the previous level that haven't been visited yet.
  • The <remarks> on TryFindMethod now describe the order breadth-first, matching the code.

Tests

  • TryFindMethodPrefersDirectParentInterfaceOverMoreDistantOne is the repro from the issue.
  • TryFindMethodInterfaceResultDoesNotChangeWhenAParentGainsABase shows that adding a base to the sibling doesn't change which interface wins.
  • TryFindMethodSearchesSharedInterfaceAncestorAtItsNearestDistance covers a diamond.
  • With the fix reverted, the first two tests fail and return IDistanceRoot. With the fix, all 217 tests pass, and the Release build of every target framework is clean.

Generated by Claude Code

… [patch]

TryFindMethod grouped an interface's inherited interfaces by how many
interfaces each one itself inherits. A direct parent with no bases landed
in the last group, behind interfaces further away, so IDerived : IBase, IX
returned IRoot.Foo(int) two levels up instead of IX.Foo(). Adding a base to
IX changed the answer.

The levels are now built breadth-first: the direct interfaces of the type
first, then their direct bases not yet visited, and so on.

Fixes #178

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW4JrXevVTQZvqzLBX1
@sonarqubecloud

sonarqubecloud Bot commented Nov 1, 2026

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit b8cf008 into main Nov 4, 2026
15 checks passed
@matt-edmondson
matt-edmondson deleted the fix/178-interface-search-by-distance branch November 4, 2026 00:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants