Skip to content

inheritors_of can report a same-named class from another namespace as an inheritor #940

Description

@merlincat11

Split out of #939 (review discussion) to keep that PR scoped to the parser bug in #935.

Problem

inheritors_of resolves the requested node, and when exact qualified-target lookup finds
nothing it falls back to the node's plain name. That fallback matches edges by bare
target plus source language, which does not establish namespace or package identity.

A/GenericBase.cs:  namespace A; class GenericBase<T> {}
B/GenericBase.cs:  namespace B; class GenericBase<T> {}
B/Child.cs:        namespace B; class Child : GenericBase<string> {}

Querying the A declaration by its qualified graph name returns B.Child, with no
caveat attached:

$ code-review-graph query inheritors_of /repo/A/GenericBase.cs::GenericBase
count: 1  results: ['Child']   confidence: None

Not specific to generics

Reproduces on main with plain class Child : PlainBase {} and two same-named
PlainBase declarations. This is the bare-name fallback, not the generic handling.

Why it matters

#935 objected to the graph making unjustified affirmative claims about inheritance. A
false positive asserted without qualification is the same failure pointing the other way.

Options

  1. Resolve the base name against namespace/package/import context before treating the
    relationship as resolved — the real fix, and the one worth doing.
  2. Attach a caveat when the fallback matched an ambiguous bare name, so the result is
    returned but not asserted. A prototype existed in fix(parser): resolve generic inheritance targets #939 (restricting the ambiguity
    count to Class/Type kinds) and was removed to keep that PR scoped.

Option 2 is a mitigation; option 1 is the fix.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions