Repository navigation
fix(kotlin): keep annotated inferred properties in the graph - #3915
nothariharan wants to merge 1 commit into
Conversation
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]>
|
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. |
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. 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— 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
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).
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]>
|
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. |
What does this PR do?
Fixes #3884.
A Kotlin class property that has an annotation and no explicit type crashes the extractor, and
_safe_extractthen drops the entire file from the graph. The reported case is:graphify updateprints one warning and keeps going:The class, the property,
ping(), and every other symbol in that file are absent (0 nodes, 0 edges). A secondgraphify updatedoes not repeat the warning, because the failure is recorded onfailed_sourcesand 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_declarationhandler,line = node.start_point[0] + 1was assigned only insideif type_node is not None. The annotation loop below that branch always readsline._kotlin_property_type_nodelooks for auser_type/nullable_type/type_reference.@Volatile var counter = 0has none: the type is inferred from0. Solineis never bound, the annotation loop raisesUnboundLocalError, and_safe_extractreturns an empty result for the file.Change
Assign
lineonce, before the type-node check, still insideif 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 ofRepro, and@Volatileis areferencesedge withcontext="attribute", which is what an annotated property with an explicit type already produced.What this does not change
@Volatile var counter: Int = 0) still emits the same attribute edge.lineis still the property node's start line.if parent_class_nid, so a file-level@Volatile val counter = 0still does not get areferencesedge, and it never hit this crash.@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.class Repro(@Volatile var inferred = 0)does not parse as aclass_parameterin tree-sitter-kotlin (the parameter is anERRORnode). That is a pre-existing grammar miss, not this bug.Type of change
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.
test_kotlin_annotated_inferred_property_keeps_the_filefails on the parent commit:failed_sources == ['Repro.kt']and stderr reports theUnboundLocalError. With this commit it requires the file to be extracted, the siblingping()method edge to survive, and aRepro→Volatilereferencesedge withcontext="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-propertybased onv8@d6eaa8a(0.9.71).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, andopenainot installed. None are intests/test_kotlin_grammar.py.Graphify-specific checklist
uv run python -m tools.skillgen --bless) when changing their source fragments. Not applicable: no skill fragment changed.skillgen --checkpassed.