Repository navigation
fix(extract): walk Scala type_definition right-hand sides (#2049) - #4037
Faisal-Fayaz wants to merge 2 commits 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]>
…abs#2049) A type alias (`type Alias = List[Int]`), an `opaque type`, and a `match type` all declare a dependency on the types they name, but the type-reference dispatch only fired for `val_definition`/`var_definition`, so these produced zero `references` edges in any context -- in contrast to a `val`/`var`, whose annotation is walked. `match_type` needed a second, independent change: the type-reference walker's recursion whitelist did not know `match_type`/`type_case_clause`, so even a correctly dispatched call on a match type's right-hand side would have resolved nothing. Both are now handled, recursing over named children exactly as `compound_type` already is. Verified field names against tree-sitter-scala 0.26.0 before writing the fix: `type_definition` carries its RHS under the `type` field for all three forms (`generic_type`, `type_identifier`, `match_type`), so the existing `child_by_field_name("type")` walk applies verbatim and no new handler is needed. File-scope aliases inherit the Graphify-Labs#2054 anchor fallback. Scope: only the edges are added. The alias still gets no node of its own, which is a separate already-accepted tradeoff shared with `val`/`given` bindings. Verified: - uv run pytest tests/test_scala_type_definition.py -q (10 passed) - 8 of the 10 new tests fail on the pre-fix tree - uv run pytest tests/ -q -> 28 failed, 6154 passed, 101 skipped; the 28 failures are byte-identical to the clean-tree baseline and none touch Scala - uv run ruff check . -> clean - uv run pyright -> 635 errors, identical to the clean-tree baseline 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.
Worth a look — the grounded gate found no coupling regressions or blocking issues, but 1 advisory finding(s) below merit a look before merge.
Formal verification. PR-changed functions: 0/2 verified (0 proven, 0 may-equivalent, 0 distinguished) · 2 not verified (1 vacuous, 1 unsupported).
Not verified on this run: \_extract\_generic (unsupported), \_scala\_collect\_type\_refs (vacuous: never exercised).
Graphify review — findings
Fixes Scala type-reference extraction so file-scope val/var bindings (Scala 3's wrapper-less style) emit references edges owned by the file node instead of vanishing from the graph. type_definition now gets the same treatment, so type aliases, opaque types and match types link to the types on their right-hand side, though the alias itself still gets no node. _scala_collect_type_refs now recurses into match_type/type_case_clause, so both the matched and the yielded type in each case are picked up.
Worth a look
- Scala type alias type parameters are emitted as spurious reference targets —
graphify/extractors/engine.py:5249· Escalate · medium- agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 754 functions depend on the 274 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 — 754 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: 689 function(s) in the blast radius were not formally verified this run
Test selection
Test selection
27 of 320 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_scala_type_definition.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 symbolsInnerCHANGELOG.md§ 0.9.1 (2026-06-28) (lines 985-995): references changed symbolsPayload
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
Could not verify: Could not verify \_scala\_collect\_type\_refs.
The verifier did not have enough to check \_scala\_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: not verifiable: all 200 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly AttributeError — names the real obstacle, not a sampling gap)
· 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
A type alias (
type Alias = List[Int]), anopaque type, and amatch typeall declare a dependency on the types they name — but the type-reference dispatch only fired forval_definition/var_definition, so these produced zeroreferencesedges of any kind, in any context. That is the asymmetry withval/var, whose annotation is walked:match_typeneeded a second, independent change: the type-reference walker's own recursion whitelist did not knowmatch_type/type_case_clause, so even a correctly dispatched call on a match type's right-hand side would still resolve nothing.Implementation
Two small changes:
Widen the dispatch tuple to include
type_definition. I verified the RHS field name against tree-sitter-scala 0.26.0 before writing the fix — all three forms carry it under the sametypefield theval/varpath already reads, so the existing walk applies verbatim with no new handler:Add
match_type/type_case_clauseto the walker whitelist, recursing over named children exactly ascompound_typeis already handled. A case clause names two real types — the one it discriminates on and the one it yields — and both are collected.File-scope aliases inherit the anchor fallback from #4036; without it, an alias at file scope is still dropped by the separate missing-container defect that PR fixes.
Scope
Edges only. The alias itself still gets no node of its own. That is a separate, already-accepted tradeoff shared with
val/givenbindings, and I deliberately left it alone rather than widening this PR. No new node type, no config change.Verification
engine.pychange and re-running).28 failed, 6136 passed), diffed test-id-by-test-id. They are missing tree-sitter grammars for erlang/R/solidity/vbnet plus ollama retry tests; none touch Scala.Tests cover all three alias forms in-trait and at file scope, the
generic_typeargument split, thematch_typeresult and matched type, that the sharedvalcontext split is preserved rather than flattened,EXTRACTEDtagging with a source location, and the self-edge guard.🤖 Generated with Claude Code