Skip to content

fix(kotlin): extract typealias declarations so references don't mint sourceless stubs - #4557

Closed
rajatnagda45 wants to merge 1 commit into
Graphify-Labs:v8from
rajatnagda45:fix/kotlin-typealias-declarations
Closed

rajatnagda45 wants to merge 1 commit into
Graphify-Labs:v8from
rajatnagda45:fix/kotlin-typealias-declarations

Conversation

@rajatnagda45

Copy link
Copy Markdown
Contributor

Closes #4553.

Problem

A Kotlin typealias is a named type, but type_alias was in neither class_types nor function_types, so the declaration was dropped from the graph. A property or parameter typed as the alias (var onClick: ClickHandler?, fun handler(h: ClickHandler)) still resolved the name ClickHandler through ensure_named_node, which minted a sourceless stub and pointed the references edge at it — even though the alias is declared in the same file.

That violates the provenance invariant (a real source-backed declaration losing to a sourceless god node; the bare-id stub becomes a cross-file hub). Scala and TypeScript already model type aliases as nodes, so Kotlin was the inconsistent outlier.

Implementation

type_alias has an identifier name (covered by name_fallback_child_types) and no body, so adding it to the Kotlin class_types emits a clean empty type node (no phantom members) that the in-file references now bind to.

Verification

  • New regression in tests/test_kotlin_typealias_declarations.py (typealias is a sourced node, references bind to it, no sourceless leftover). Fails on pre-fix v8, passes after.
  • Commands run:
    • python -m pytest tests/ -q --ignore=tests/test_security.py → 8330 passed, 15 skipped (deselecting the live-DNS security tests and the built-wheel test).
    • python -m pytest tests/ -k kotlin → 65 passed (no regressions).
    • ruff check . → clean.
    • pyright graphify/extract.py → unchanged from baseline (0 added).

Limitations

The alias's underlying-type reference (ClickHandler -> Unit) is not emitted; this change models the alias as a named type node so references stop fabricating a sourceless stub.

…sourceless stubs

A Kotlin `typealias` is a named type, but `type_alias` was in neither
`class_types` nor `function_types`, so the declaration was dropped from the
graph. A property or parameter typed as the alias (`var onClick: ClickHandler?`,
`fun handler(h: ClickHandler)`) still resolved the name `ClickHandler` through
`ensure_named_node`, which minted a *sourceless* stub and pointed the
`references` edge at it — even though the alias is declared in the same file.

That violates the provenance invariant: a real source-backed declaration must
not lose to a sourceless god node (and a bare-id stub becomes a cross-file hub
shared by every same-named reference in the corpus). Scala and TypeScript
already model type aliases as nodes, so Kotlin was the inconsistent outlier.

`type_alias` has an `identifier` name (covered by `name_fallback_child_types`)
and no body, so adding it to the Kotlin `class_types` emits a clean empty type
node (no phantom members) that the in-file references now bind to.
@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @rajatnagda45. A maintainer will review it soon.

Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions.

A couple of things that speed up review: make sure the test suite passes on Python 3.10 and 3.13, and that the change keeps extraction deterministic.

@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Oct 18, 2026

@graphify-labs graphify-labs Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graphify reviewed this change.

No issues found by static checks — no coupling regressions or blocking issues in the code graph. That is not the same as safe to merge: see what was not checked.

Not checked: tests were not run; no formal proof of the changed code.


Graphify review — findings

Adds Kotlin typealias declarations to the extractor as real, source-backed type nodes by registering type_alias in the Kotlin class_types. Previously the declaration was dropped, so a field or parameter typed as the alias (e.g. var onClick: ClickHandler?) minted a sourceless stub node and the references edge pointed at that instead of the in-file declaration. A new test checks that the alias node has a source_file, that no sourceless ClickHandler node remains, and that references bind to the alias.

No blocking issues surfaced.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 3114 functions depend on the 329 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: extract() — 976 callers, 59 callees

Verification — 3114 functions in the blast radius were not formally verified this run (proofs are advisory here).

Gate & verification

graphify gate

PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.

Advisory (not blocking):

  • verification_scope: 2876 function(s) in the blast radius were not formally verified this run

Test selection

Test selection

199 of 433 test file(s) selected (46%) via static blast radius.

  • tests/test_affected_overrides.py — impact
  • tests/test_astro_extraction.py — impact
  • tests/test_astro_import_ids.py — impact
  • tests/test_blade_extractor.py — impact
  • tests/test_build.py — impact
  • tests/test_builtin_global_type_refs.py — impact
  • tests/test_c_include_resolution.py — impact
  • tests/test_cache.py — impact
  • tests/test_case_sensitive_resolution.py — impact
  • tests/test_cjs_module_extension.py — impact
  • tests/test_cobol_extractor.py — impact
  • tests/test_cpp_method_declarations.py — impact
  • tests/test_cpp_nested_and_cli.py — impact
  • tests/test_cpp_objc_cross_file_calls.py — impact
  • tests/test_cpp_template_type_params.py — impact
  • tests/test_cross_extension_reexport_self_cycle.py — impact
  • tests/test_cross_language_call_resolution.py — impact
  • tests/test_cross_repo_external_call_guards.py — impact
  • tests/test_cross_repo_member_calls.py — impact
  • tests/test_csharp_call_site_generic_args.py — impact
  • tests/test_csharp_enum_members.py — impact
  • tests/test_csharp_field_generic_args.py — impact
  • tests/test_csharp_foreach_loop_variable.py — impact
  • tests/test_csharp_generic_callsites.py — impact
  • tests/test_csharp_interface_dispatch.py — impact
  • tests/test_csharp_member_calls.py — impact
  • tests/test_csharp_member_chain_calls.py — impact
  • tests/test_csharp_member_nodes.py — impact
  • tests/test_csharp_object_creation.py — impact
  • tests/test_csharp_partial_classes.py — impact
  • tests/test_csharp_tuple_type_refs.py — impact
  • tests/test_csharp_type_resolution.py — impact
  • tests/test_csharp_underscore_collisions.py — impact
  • tests/test_csharp_var_call_return_type.py — impact
  • tests/test_csharp_verbatim_interpolation.py — impact
  • tests/test_definition_file_portability.py — impact
  • tests/test_detect.py — impact
  • tests/test_dotnet.py — impact
  • tests/test_duplicate_annotation_edges.py — impact
  • tests/test_ejs_extractor.py — impact
  • tests/test_elixir_defdelegate.py — impact
  • tests/test_elixir_import_resolution.py — impact
  • tests/test_elixir_keyword_def_calls.py — impact
  • tests/test_elixir_qualified_calls.py — impact
  • tests/test_elixir_unqualified_call_scope.py — impact
  • tests/test_erlang_extractor.py — impact
  • tests/test_ext_tagged_id_clash.py — impact
  • tests/test_extract.py — impact
  • tests/test_extract_cache_location.py — impact
  • tests/test_extract_path_memo.py — impact
  • … and 149 more

Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.

· 1 more finding(s) on lines outside this diff (see the check run).

@safishamsi

Copy link
Copy Markdown
Member

Landed in 0.9.93, cherry-picked to preserve your authorship. A Kotlin typealias declaration is now extracted, so a field or parameter typed as the alias resolves to it instead of minting a sourceless cross-file stub. Thanks @rajatnagda45. Live on PyPI: https://pypi.org/project/graphifyy/0.9.93/

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

Labels

contributor Pull request from a returning community contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Kotlin typealias declarations dropped, so in-file references mint a sourceless god node

2 participants