Skip to content

fix(kotlin): keep annotated inferred properties in the graph - #3915

Closed
nothariharan wants to merge 1 commit into
Graphify-Labs:v8from
nothariharan:fix/3884-kotlin-annotated-property
Closed

nothariharan wants to merge 1 commit into
Graphify-Labs:v8from
nothariharan:fix/3884-kotlin-annotated-property

Conversation

@nothariharan

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes #3884.

A Kotlin class property that has an annotation and no explicit type crashes the extractor, and _safe_extract then drops the entire file from the graph. The reported case is:

class Repro {
    @Volatile
    var counter = 0

    fun ping() { }
}

graphify update prints one warning and keeps going:

warning: skipped Repro.kt (UnboundLocalError: cannot access local variable 'line' where it is not associated with a value)

The class, the property, ping(), and every other symbol in that file are absent (0 nodes, 0 edges). A second graphify update does not repeat the warning, because the failure is recorded on failed_sources and the empty result is what the incremental path sees. In the report's Android project this removed 4 of 70 Kotlin files, including the whole Android layer, while the rest of the graph looked fine.

Cause

In the Kotlin property_declaration handler, line = node.start_point[0] + 1 was assigned only inside if type_node is not None. The annotation loop below that branch always reads line.

_kotlin_property_type_node looks for a user_type / nullable_type / type_reference. @Volatile var counter = 0 has none: the type is inferred from 0. So line is never bound, the annotation loop raises UnboundLocalError, and _safe_extract returns an empty result for the file.

Change

Assign line once, before the type-node check, still inside if parent_class_nid. That is the same expression the explicit-type path already used. The type-reference walk and the initializer seeding are unchanged.

After the fix the file stays in the graph, ping() is still a method of Repro, and @Volatile is a references edge with context="attribute", which is what an annotated property with an explicit type already produced.

What this does not change

  • A property with an explicit type (@Volatile var counter: Int = 0) still emits the same attribute edge. line is still the property node's start line.
  • A property with no annotation never entered the loop, so it still emits no annotation edge.
  • Top-level properties stay class-gated. The annotation loop is still inside if parent_class_nid, so a file-level @Volatile val counter = 0 still does not get a references edge, and it never hit this crash.
  • Use-site targets (@field:Volatile, @get:JvmName("count")) and argument forms (@Suppress("NAME")) already had their names parsed by _kotlin_annotation_names. An inferred-type property with one of those used to drop the file; it now gets the same attribute edge. The use-site keyword itself is not turned into a node.
  • Primary-constructor parameters are a different path and are not touched. class Repro(@Volatile var inferred = 0) does not parse as a class_parameter in tree-sitter-kotlin (the parameter is an ERROR node). That is a pre-existing grammar miss, not this bug.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Tests or CI
  • Refactor
  • Security fix

Verification & Invariants

The invariant: an extractor exception on one declaration must not discard the rest of the file, and an annotation on an inferred-type property must be recorded the same way as an annotation on an explicit type.

  • Read the CONTRIBUTING.md guide.
  • Reproduced the issue and identified the invariant.
  • Made the smallest fix necessary.
  • Added a regression test (if bug fix) or isolated boundary test.
  • Kept the PR description synchronized with the final implementation.
  • Documented any limitations / unsupported cases explicitly.

test_kotlin_annotated_inferred_property_keeps_the_file fails on the parent commit: failed_sources == ['Repro.kt'] and stderr reports the UnboundLocalError. With this commit it requires the file to be extracted, the sibling ping() method edge to survive, and a Repro → Volatile references edge with context="attribute". The explicit-type control passes on both the parent and this commit.

No persisted graph or cache format changes. AST extraction stays deterministic. No skill fragments were edited, so skillgen was not regenerated.

How was this tested?

Windows, Python 3.12, branch fix/3884-kotlin-annotated-property based on v8 @ d6eaa8a (0.9.71).

uv run pytest tests/test_kotlin_grammar.py::test_kotlin_annotated_inferred_property_keeps_the_file tests/test_kotlin_grammar.py::test_kotlin_annotated_explicit_type_property_still_references -q
# before the hoist: 1 failed (failed_sources == ['Repro.kt']), 1 passed
# after the hoist: 2 passed

uv run pytest tests/test_kotlin_grammar.py -q
# 25 passed

uv run ruff check graphify/extractors/engine.py tests/test_kotlin_grammar.py
# All checks passed

uv run pre-commit run --files graphify/extractors/engine.py tests/test_kotlin_grammar.py
# skillgen --check passed
# ruff passed

uv run pytest tests/ -q --tb=line
# 5913 passed, 115 skipped, 47 failed

The 47 full-suite failures are from this Windows environment, not from the Kotlin change. They are missing optional extractors (tree-sitter-language-pack, solidity, vb-dotnet), POSIX-only APIs (os.mkfifo, socket.AF_UNIX), path-separator and console-encoding checks, a file lock on a deleted cwd, and openai not installed. None are in tests/test_kotlin_grammar.py.

Graphify-specific checklist

  • I updated generated skill artifacts (uv run python -m tools.skillgen --bless) when changing their source fragments. Not applicable: no skill fragment changed. skillgen --check passed.
  • I confirmed that AST/structural extraction remains deterministic (no ambient state dependencies like ENV variables).
  • I reviewed changes for security implications (no unsafe interpolation into shell/Python).
  • I confirmed no API keys or local-only graph data are included.
  • (If applicable) I disclosed AI authorship in my commit messages.

An annotation on a class property with no explicit type never assigned
`line`, so the annotation loop raised UnboundLocalError and _safe_extract
dropped the whole file. Set `line` before the type-node check so the file
and its attribute edge both survive.

Fixes Graphify-Labs#3884

Co-Authored-By: Grok 4.7 <[email protected]>
@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @nothariharan. 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.

@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.

Looks safe to merge — no coupling regressions and no blocking issues, checked against the code graph (not a self-assessment).

Formal verification. No changes could be formally verified in this run.


Graphify review — findings

Fixes an UnboundLocalError in _extract_generic where Kotlin class properties with an annotation but no explicit type (e.g. @Volatile var counter = 0) crashed the annotation loop, causing _safe_extract to drop every node in the file. line is now assigned unconditionally before the type-node branch, so annotation reference edges emit and sibling declarations survive.

No blocking issues surfaced.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 746 functions depend on the 271 functions this change touches.

Health — this change adds coupling hotspots:

  • new: _extract_generic() — 18 callers, 29 callees
  • new: extract_js() — 87 callers, 4 callees
  • new: extract_xaml() — 19 callers, 17 callees
  • new: extract_objc() — 27 callers, 9 callees
  • new: extract_julia() — 19 callers, 7 callees
  • new: extract_cpp() — 29 callers, 3 callees
  • new: extract_vue() — 10 callers, 7 callees
  • new: walk() — 1 callers, 64 callees
  • …and 9 more — each is listed as a finding

Verification — 746 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: 683 function(s) in the blast radius were not formally verified this run

Test selection

Test selection

26 of 304 test file(s) selected (9%) via static blast radius.

  • tests/test_astro_extraction.py — impact
  • tests/test_build.py — impact
  • tests/test_cjs_module_extension.py — impact
  • tests/test_cpp_nested_and_cli.py — impact
  • tests/test_dotnet.py — impact
  • tests/test_extract.py — impact
  • tests/test_extract_php_closures.py — impact
  • tests/test_import_extension_resolution.py — impact
  • tests/test_indirect_call_block_scoped_shadow.py — impact
  • tests/test_indirect_dispatch.py — impact
  • tests/test_indirect_dispatch_assign_return.py — impact
  • tests/test_indirect_dispatch_getattr.py — impact
  • tests/test_js_exported_scalar_bindings.py — impact
  • tests/test_kotlin_grammar.py — impact, changed-test
  • tests/test_languages.py — impact
  • tests/test_multilang.py — impact
  • tests/test_python_underscore_resolution.py — impact
  • tests/test_rationale.py — impact
  • tests/test_ruby_resolution.py — impact
  • tests/test_scala_self_type.py — impact
  • tests/test_swift_computed_properties.py — impact
  • tests/test_swift_protocol_requirements.py — impact
  • tests/test_trailing_newline_not_a_syntax_error.py — impact
  • tests/test_ts_new_expression_calls.py — impact
  • tests/test_typescript_module_extensions.py — impact
  • tests/test_vue_extraction.py — impact

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.

Formal verification

Could not verify: Could not verify \_extract\_generic.

The verifier did not have enough to check \_extract\_generic, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: no capturable inputs from the test suite; property tier: parameter `config` is annotated `LanguageConfig` — outside the synthesizable primitive/collection set

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

safishamsi pushed a commit that referenced this pull request Sep 29, 2026
The code fix landed via #3915 (byte-identical hoist). Keep @harshaygadekar's
independent regression test for #3884 (found simultaneously) for coverage
and contributor credit.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
safishamsi added a commit that referenced this pull request Sep 29, 2026
…ction

HTML node-info field fix (#3918), Kotlin annotated-inferred-property
crash (#3915/#3899), SQL DDL-before-DO (#3900), Razor @functions (#3908),
Blade @extends (#3907), and imported-module resolution (#3898).

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

Copy link
Copy Markdown
Member

Shipped in v0.9.72 (now on PyPI) via an authorship-preserving cherry-pick, so your commit keeps contributor-graph credit. Thanks @nothariharan! Annotated inferred-type Kotlin properties no longer crash extraction.

Release: https://github.com/Graphify-Labs/graphify/releases/tag/v0.9.72

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.

Kotlin: class property with an annotation and no explicit type drops the whole file (UnboundLocalError: 'line' unbound)

2 participants