fix(kotlin): resolve qualified supertype to its tail type name#1793
Open
Synvoya wants to merge 1 commit into
Open
fix(kotlin): resolve qualified supertype to its tail type name#1793Synvoya wants to merge 1 commit into
Synvoya wants to merge 1 commit into
Conversation
_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`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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()emitsFoo --inherits--> cominstead ofFoo --inherits--> Base, collapsing every qualified base/interface onto a boguscomnode.Root cause
_kotlin_user_type_namereturned the first identifier child of auser_typenode. The tree-sitter-kotlin grammar stores a qualified name as flat identifier children:So the walker returned
com.Minimal repro
Before:
inherits {(Foo, com)},implements {(Foo, com)}.Fix
Scan the direct children and keep the last identifier/
type_identifiersegment. Type arguments live in a separatetype_argumentschild (not an identifier), so generics likecom.ex.Container<String>correctly resolve toContainer. 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-segmentuser_typestill returns that segment.After the fix:
Foo --inherits--> BaseFoo --implements--> IfaceTesting
test_kotlin_qualified_supertype_uses_tail_nametotests/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.