Repository navigation
fix(kotlin): hoist property line calculation to prevent UnboundLocalError on annotated properties (#3884) - #3899
Conversation
…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.
|
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. |
There was a problem hiding this comment.
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— impacttests/test_build.py— impacttests/test_cjs_module_extension.py— impacttests/test_cpp_nested_and_cli.py— impacttests/test_dotnet.py— impacttests/test_extract.py— impacttests/test_extract_php_closures.py— impacttests/test_import_extension_resolution.py— impacttests/test_indirect_call_block_scoped_shadow.py— impacttests/test_indirect_dispatch.py— impacttests/test_indirect_dispatch_assign_return.py— impacttests/test_indirect_dispatch_getattr.py— impacttests/test_js_exported_scalar_bindings.py— impacttests/test_kotlin_grammar.py— impact, changed-testtests/test_languages.py— impacttests/test_multilang.py— impacttests/test_python_underscore_resolution.py— impacttests/test_rationale.py— impacttests/test_ruby_resolution.py— impacttests/test_scala_self_type.py— impacttests/test_swift_computed_properties.py— impacttests/test_swift_protocol_requirements.py— impacttests/test_trailing_newline_not_a_syntax_error.py— impacttests/test_ts_new_expression_calls.py— impacttests/test_typescript_module_extensions.py— impacttests/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).
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]>
…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]>
|
Superseded by #3915, which shipped the byte-identical |
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 = 0or@Inject val id = 1) crashed with:UnboundLocalError: cannot access local variable 'line' where it is not associated with a value.Because
_safe_extractcatches extractor crashes and returns empty results, the entire.ktfile 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] + 1was defined only withinif type_node is not None:. When a property has no explicit type node,type_nodeisNone, solinewas never assigned before being passed toensure_named_node(anno_name, line)in the subsequent annotation loop.Fix
Hoist
line = node.start_point[0] + 1to the top of theif parent_class_nid:block, matching the pattern used in the adjacent Swift extractor. This ensureslineis unconditionally available for both explicit-type properties and inferred-type properties.Evidence
Before Fix
After Fix
Verification
test_kotlin_class_property_annotation_without_explicit_typeintests/test_kotlin_grammar.py.uv run pytest tests/test_kotlin_grammar.py(all 24 tests passed).uv run ruff check graphify/extractors/engine.py tests/test_kotlin_grammar.py(clean).uv run python -m tools.skillgen --check(134 artifacts match).