Repository navigation
fix(extract): keep Scala file-scope val/var type references (#2054) - #4036
Faisal-Fayaz wants to merge 1 commit into
Conversation
…-Labs#2054) Scala 3 allows `val`/`var` to be written directly at file scope with no enclosing object/class/trait. The `val_definition`/`var_definition` type-reference dispatch was gated on `and parent_class_nid`, so a file-scope binding produced no node and no edge of any kind, while the byte-identical definition nested one level inside any container resolved correctly. The missing container was the only difference: both positions parse to the same node type carrying the same `type` field. This is the Scala instance of a generic defect in the walker's default recursion path that had already caused and been fixed once for Python (Graphify-Labs#1050) -- a position that legitimately has no container must fall back to the file node rather than be skipped. The fix reuses the `owner_nid = parent_class_nid or file_nid` idiom already present in the property branch above, and moves the self-reference guard onto the same anchor so a file-scope binding cannot mint an edge from the file node to itself. Behaviour is unchanged for class-nested bindings; a regression test pins that case explicitly. Verified: - uv run pytest tests/test_scala_top_level_binding.py -q (8 passed) - 6 of the 8 new tests fail on the pre-fix tree, 2 pass either way (the in-class control, and the self-edge guard which is trivially empty before the fix and meaningful after it) - uv run pytest tests/ -q -> 28 failed, 6144 passed, 101 skipped; the 28 failures are byte-identical to the clean-tree baseline (missing tree-sitter grammars for erlang/R/solidity/vbnet, plus ollama retry tests) and none touch Scala - uv run ruff check . -> clean - uv run pyright -> 635 errors, identical to the clean-tree baseline (pre-existing debt; this change adds none) Co-Authored-By: Claude <[email protected]>
|
Thanks for the pull request, @Faisal-Fayaz. 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. PR-changed functions: 0/1 verified (0 proven, 0 may-equivalent, 0 distinguished) · 1 not verified (1 unsupported).
Not verified on this run: \_extract\_generic (unsupported).
Graphify review — findings
Fixes Scala 3 file-scope val/var bindings disappearing from the graph: their type references now fall back to the file node as owner instead of being skipped when there is no enclosing class. The self-reference guard follows the same owner, so a binding typed with the file's own stem doesn't create a file → file edge. In-class bindings keep their class-owned edges, and new tests cover the field vs generic_arg context, the EXTRACTED confidence tag, and per-line source locations.
No blocking issues surfaced. 2 lower-confidence candidates did not survive cross-model review.
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 740 functions depend on the 260 functions this change touches.
Health — this change adds coupling hotspots:
- new:
_extract_generic()— 18 callers, 30 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()— 31 callers, 3 callees - new:
extract_vue()— 10 callers, 7 callees - new:
walk()— 1 callers, 67 callees - …and 9 more — each is listed as a finding
Verification — 740 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: 675 function(s) in the blast radius were not formally verified this run
Test selection
Test selection
26 of 319 test file(s) selected (8%) 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_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_scala_top_level_binding.py— impact, changed-testtests/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.
Docs that may be stale (advisory)
CHANGELOG.md§ 0.9.22 (2026-07-20) (lines 639-648): references changed symbolsInner
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).
|
Shipped in v0.9.75 (live on PyPI as Closing as shipped. |
Problem
Scala 3 drops the boilerplate wrapper:
val/varcan be written directly at file scope with no enclosingobject/class/trait. Theval_definition/var_definitiontype-reference dispatch was gated onand parent_class_nid, so a file-scope binding produced no node and no edge of any kind, while the byte-identical definition nested one level inside any container resolved correctly.The missing container was the only difference. I verified this against tree-sitter-scala 0.26.0 before writing the fix — both positions parse to the same node type carrying the same
typefield:This is the Scala instance of a generic defect in the walker's default recursion path that had already caused and been fixed once for Python (#1050) — a position that legitimately has no container must fall back to the file node rather than be skipped.
Implementation
One anchor fallback in the existing dispatch, reusing the
owner_nid = parent_class_nid or file_nididiom already present in the property branch above:and parent_class_nidfrom the gateowner_nid = parent_class_nid or file_nidowner_nid, and move the self-reference guard onto the same anchor so a file-scope binding cannot mint an edge from the file node to itselfClass-nested bindings are untouched; a regression test pins that case explicitly.
Scope
Edges only. No new node type, no config change, no skillgen output (
_SCALA_CONFIGregisters none of these node types — they are handled ad-hoc in the walker).Verification
28 failed, 6136 passed), which I captured on an unmodified checkout and diffed test-id-by-test-id. They are missing tree-sitter grammars for erlang/R/solidity/vbnet plus ollama retry tests, and none touch Scala.New tests cover: file-scope
valandvar, the in-class control, a file-scope type that resolves to a real declaration elsewhere, the no-self-edge guard,EXTRACTEDconfidence tagging, non-nullsource_location, and that a generic annotation keeps itsgeneric_argcontext distinct from a plainfieldone.Limitations
contains-from-file model already produces; collapsing them would need a node for the binding itself, which is out of scope here.🤖 Generated with Claude Code