Skip to content

fix(kotlin): resolve qualified supertype to its tail type name - #1793

Closed
Synvoya wants to merge 1 commit into
Graphify-Labs:v8from
Synvoya:fix/kotlin-qualified-supertype
Closed

Synvoya wants to merge 1 commit into
Graphify-Labs:v8from
Synvoya:fix/kotlin-qualified-supertype

Conversation

@Synvoya

@Synvoya Synvoya commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Bug

A Kotlin class with a qualified supertype resolves its heritage edge to the package root instead of the type. class Foo : com.example.Base() emits Foo --inherits--> com instead of Foo --inherits--> Base, collapsing every qualified base/interface onto a bogus com node.

Root cause

_kotlin_user_type_name returned the first identifier child of a user_type node. The tree-sitter-kotlin grammar stores a qualified name as flat identifier children:

user_type "com.example.Base"
  identifier "com"
  .
  identifier "example"
  .
  identifier "Base"

So the walker returned com.

Minimal repro

class Foo : com.example.Base(), com.example.Iface

Before: inherits {(Foo, com)}, implements {(Foo, com)}.

Fix

Scan the direct children and keep the last identifier/type_identifier segment. Type arguments live in a separate type_arguments child (not an identifier), so generics like com.ex.Container<String> correctly resolve to Container. This mirrors the existing C++ qualified-base handling that uses the unqualified tail. Simple (Base) and delegated (Bar by baz) supertypes are unaffected — a single-segment user_type still returns that segment.

After the fix:

  • Foo --inherits--> Base
  • Foo --implements--> Iface

Testing

  • Added test_kotlin_qualified_supertype_uses_tail_name to tests/test_languages.py. Fails before, passes after.
  • tests/test_languages.py: 315 passed, 13 skipped — the existing Kotlin simple-supertype and interface-delegation tests still pass.

_kotlin_user_type_name returned the first identifier child of a user_type
node. For a qualified supertype like `com.example.Base` the Kotlin grammar
stores the segments as flat identifier children (com, example, Base), so
the walker returned the package root `com` instead of `Base`, collapsing
every qualified base/interface onto a bogus `com` node.

Scan the direct children and keep the last identifier/type_identifier
segment (type arguments live in a separate type_arguments child, so
generics are ignored). Mirrors the C++ qualified-base handling that uses
the unqualified tail.

Adds a regression test for `class Foo : com.example.Base(), com.example.Iface`.
safishamsi pushed a commit that referenced this pull request Aug 30, 2026
A qualified Kotlin supertype (`class Foo : com.example.Base()`) resolved to the first
identifier (`com`), collapsing distinct bases onto a bogus node. Take the last segment of the
user type (handling generics like `Container<String>` -> `Container`), so the edge targets
the real base; simple and delegated supertypes are unaffected.
safishamsi added a commit that referenced this pull request Aug 30, 2026
Ships two batches: the robot/defang/watch/semantic-guard set — Robot Framework extractor
(#3192), generalized control-token defang (#3183), watch unresolved-link preservation
(#3190), unverified-semantic-loss guard (#3203), hook-guard search detection (#3121),
stale-SKILL.md backup (#3144), report/wiki count fixes (#3148/#3127); and a rescued batch of
@Synvoya cross-language inheritance-edge corrections (JS #1790, PHP #1791, Scala #1792/#1794,
Kotlin #1793, C# #1817, Go #1818) that had been buried in the backlog for ~7 weeks.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@safishamsi

Copy link
Copy Markdown
Member

Shipped in v0.9.53 via authorship-preserving cherry-pick so you keep contributor-graph credit. Thanks @Synvoya — this was verified still-live on the current tree and landed as part of a cross-language heritage-edge batch. Release: https://github.com/Graphify-Labs/graphify/releases/tag/v0.9.53

@safishamsi safishamsi closed this Aug 30, 2026
Soumyadip2003-AI added a commit to Soumyadip2003-AI/graphify that referenced this pull request Sep 2, 2026
…hify-Labs#3277)

`extends (\w+)` and `implements ([\w,\s]+)` both stop at the first `.`, so a
namespace-qualified base was truncated to its namespace. Two silent
consequences: a node was fabricated for the namespace (`Database`, `Outer`) and
the heritage edge pointed at it, and because the capture never reached the
comma, every remaining interface in the list was dropped -
`implements Database.Batchable<sObject>, Schedulable` lost `Schedulable`
entirely. That shape is the canonical scheduled batch job in Salesforce, and the
fabricated `Database` node collected an edge from every batch class in the repo.

Reuse the `_TYPE` expression for both clauses and route each through a
`heritage_names()` helper that splits on top-level commas only - so a generic
argument list (`Map<String, Object>`) is not shredded into fragments - then
drops generic arguments and takes the tail segment. This is the tail-name
treatment Kotlin (Graphify-Labs#1793) and Scala (Graphify-Labs#1794) already use. Interface `extends`
goes through the same helper. Extraction of the existing fixtures is unchanged.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01UEfivKVYzq1e5E6hJHiuKi
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.

2 participants