Skip to content

fix(kotlin): hoist property line calculation to prevent UnboundLocalError on annotated properties (#3884) - #3899

Closed
harshaygadekar wants to merge 1 commit into
Graphify-Labs:v8from
harshaygadekar:fix/kotlin-property-unbound-line
Closed

harshaygadekar wants to merge 1 commit into
Graphify-Labs:v8from
harshaygadekar:fix/kotlin-property-unbound-line

Conversation

@harshaygadekar

Copy link
Copy Markdown
Contributor

Fixes #3884

Summary

When extracting Kotlin class properties in engine.py, properties with an annotation and an inferred/implicit type (e.g. @Volatile var counter = 0 or @Inject val id = 1) crashed with:
UnboundLocalError: cannot access local variable 'line' where it is not associated with a value.

Because _safe_extract catches extractor crashes and returns empty results, the entire .kt file was silently dropped from the graph (0 nodes, 0 edges).

Root Cause

In graphify/extractors/engine.py (around line 4844), line = node.start_point[0] + 1 was defined only within if type_node is not None:. When a property has no explicit type node, type_node is None, so line was never assigned before being passed to ensure_named_node(anno_name, line) in the subsequent annotation loop.

Fix

Hoist line = node.start_point[0] + 1 to the top of the if parent_class_nid: block, matching the pattern used in the adjacent Swift extractor. This ensures line is unconditionally available for both explicit-type properties and inferred-type properties.

Evidence

Before Fix

$ uv run python contribution-docs/reproduction-scripts/reproduce_issue_3884.py
  warning: skipped C:\Users\...\Repro.kt (UnboundLocalError: cannot access local variable 'line' where it is not associated with a value)
============================================================
Issue #3884 Reproduction Results:
Extracted nodes count: 0
Extracted edges count: 0

[FAILED] Entire Kotlin file was DROPPED (0 nodes, 0 edges)!

After Fix

$ uv run python contribution-docs/reproduction-scripts/reproduce_issue_3884.py
============================================================
Issue #3884 Reproduction Results:
Extracted nodes count: 3
Extracted edges count: 2
  Node: repro (Repro.kt)
  Node: repro_repro (Repro)
  Node: volatile (Volatile)
  Edge: repro --contains--> repro_repro
  Edge: repro_repro --references--> volatile

[PASSED] Class extracted and annotation edge created cleanly.

Verification

  • Added regression test test_kotlin_class_property_annotation_without_explicit_type in tests/test_kotlin_grammar.py.
  • Ran uv run pytest tests/test_kotlin_grammar.py (all 24 tests passed).
  • Ran uv run ruff check graphify/extractors/engine.py tests/test_kotlin_grammar.py (clean).
  • Ran uv run python -m tools.skillgen --check (134 artifacts match).

…rror on annotated properties (Graphify-Labs#3884)

In graphify/extractors/engine.py, when a Kotlin class property has an annotation and relies on type inference without an explicit type (e.g. @volatile var counter = 0), _kotlin_property_type_node returned None. Because line was only assigned inside if type_node is not None:, line remained unbound when the subsequent annotation loop attempted to call ensure_named_node(anno_name, line), raising UnboundLocalError and causing _safe_extract to drop the entire file.

Hoist line = node.start_point[0] + 1 to the top of if parent_class_nid:, matching the adjacent Swift extractor pattern and ensuring line is unconditionally available.
Copilot AI lite review requested due to automatic review settings September 28, 2026 17:02

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @harshaygadekar. 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. 7 change(s) tested, no difference found (not proven).


Graphify review — findings

Fixes an UnboundLocalError on Kotlin class properties that have an annotation but no explicit type, by hoisting the line assignment in _extract_generic above the type-node check so it is always bound before the annotation-reference path uses it. Adds a regression test covering an annotated, type-inferred property emitting the expected class→annotation attribute reference edge without dropping the file.

No blocking issues surfaced.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 743 functions depend on the 269 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 — 743 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: 680 function(s) in the blast radius were not formally verified this run

Test selection

Test selection

26 of 302 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

Verification did not run: Verification did not run for \_resolve\_python\_module\_path.

The verification could not execute (an environment/toolchain issue, not a statement about the code).

Guarantee: No guarantee, the check itself did not complete.

Note: Detail: harness produced no verdict (rc=124): timeout after 30s

Verification did not run: Verification did not run for \_resolve\_python\_namespace\_dir.

The verification could not execute (an environment/toolchain issue, not a statement about the code).

Guarantee: No guarantee, the check itself did not complete.

Note: Detail: harness produced no verdict (rc=124): timeout after 30s

Could not verify: Could not verify extract.

The verifier did not have enough to check extract, 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: not verifiable: all 90 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly TypeError — names the real obstacle, not a sampling gap)

Could not verify: Could not verify \_csharp\_collect\_type\_refs.

The verifier did not have enough to check \_csharp\_collect\_type\_refs, 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 `skip` is annotated `frozenset[str] | None` — outside the synthesizable primitive/collection set

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

No difference found (not proven): No behavior difference found in \_to\_absolute\_from\_storage (not a proof).

The verifier ran both versions of \_to\_absolute\_from\_storage on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.

Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.

Note: An input the sampler did not try could still differ.

Could not verify: Could not verify \_collapse\_manifest\_duplicates.

The verifier did not have enough to check \_collapse\_manifest\_duplicates, 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 `items` is annotated `Iterable` — outside the synthesizable primitive/collection set

Could not verify: Could not verify \_rebuild\_lock.

The verifier did not have enough to check \_rebuild\_lock, 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: not verifiable: all 9 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous

No difference found (not proven): No behavior difference found in extract\_sql (not a proof).

The verifier ran both versions of extract\_sql on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.

Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.

Note: An input the sampler did not try could still differ.

No difference found (not proven): No behavior difference found in \_print\_banner (not a proof).

The verifier ran both versions of \_print\_banner on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.

Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.

Note: An input the sampler did not try could still differ.

Could not verify: Could not verify \_fetch\_tweet.

The verifier did not have enough to check \_fetch\_tweet, 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: not verifiable: all 200 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly non-reproducing divergences under module context — load-time entropy, never a sound refutation — names the real obstacle, not a sampling gap)

No difference found (not proven): No behavior difference found in \_build\_link\_index (not a proof).

The verifier ran both versions of \_build\_link\_index on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.

Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.

Note: An input the sampler did not try could still differ.

No difference found (not proven): No behavior difference found in \_redact\_value (not a proof).

The verifier ran both versions of \_redact\_value on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.

Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.

Note: An input the sampler did not try could still differ.

No difference found (not proven): No behavior difference found in \_cpp\_preprocess (not a proof).

The verifier ran both versions of \_cpp\_preprocess on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.

Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.

Note: An input the sampler did not try could still differ.

No difference found (not proven): No behavior difference found in extract\_r (not a proof).

The verifier ran both versions of extract\_r on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.

Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.

Note: An input the sampler did not try could still differ.

· 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

Superseded by #3915, which shipped the byte-identical line-hoist fix for #3884 in v0.9.72. You and @nothariharan reproduced the same bug simultaneously — your independent regression test (test_kotlin_class_property_annotation_without_explicit_type) was kept via an authorship-preserving cherry-pick, so you keep contributor-graph credit. Thanks @harshaygadekar!

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

@safishamsi safishamsi closed this Sep 29, 2026
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)

3 participants