fix(scala): dispatch self-type annotations to requires edges (#2052) - #2245
Closed
Yyunozor wants to merge 1 commit into
Closed
fix(scala): dispatch self-type annotations to requires edges (#2052)#2245Yyunozor wants to merge 1 commit into
Yyunozor wants to merge 1 commit into
Conversation
…y-Labs#2052) self_type (`self: Logging with Database =>`, `this: T =>`) was never dispatched on anywhere in the Scala extractor, so a trait/class's structural precondition on its enclosing type produced zero edges, in any context. The type node sits at a fixed position among self_type's unnamed-field children (binder identifier first, type second when present), and _scala_collect_type_refs already handles every shape that position can take (type_identifier, compound_type for `with`, refinement bodies) -- reused unchanged, one new dispatch branch. Also add the new `requires` relation to DEFAULT_AFFECTED_RELATIONS, mirroring how `indirect_call` was wired into blast-radius traversal when it was introduced, so `graphify affected` follows it like the existing inherits/mixes_in/embeds structural relations. Covers: single type, `with`-compound, structural refinement (base type only, matching how refinement bodies are already unscanned elsewhere), the binder-only `self =>` shape (no requires edge), coexistence with an unrelated `extends`, and a plain class without a self-type (no spurious edge).
Collaborator
|
Thanks @Yyunozor. Shipped in v0.9.29 (cherry-picked to v8). Note: the requires-edge emission fires for self-types in a class/object; the trait cake-pattern case (#2052) additionally needs trait-as-class recognition, tracked in #2247. Closed-unmerged here, but it's in the release: https://github.com/Graphify-Labs/graphify/releases/tag/v0.9.29 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2052
Bug
self_type(self: Logging with Database =>,this: T =>) was never dispatched on anywhere in the Scala extractor, so a trait/class's structural precondition on its enclosing type produced zero edges, in any context.Fix
One new dispatch branch in
graphify/extractors/engine.py, next toval_definition/var_definition.self_type's children carry no field names, so the type node is found positionally: binder identifier first, type (when present) second.self =>binds a name with no type, solen(named) < 2correctly yields no type node instead of misreading the binder._scala_collect_type_refsalready handles every shape the type position can take (type_identifier,compound_typeforwith, refinement bodies) — reused unchanged, matching the issue's proposed diff. Edges use a newrequiresrelation, following the issue's own proposal; the label stays your call per its open question.Also added
requirestoDEFAULT_AFFECTED_RELATIONS(graphify/affected.py), mirroring howindirect_callwas wired in when introduced, sographify affectedfollows it likeinherits/mixes_in/embeds. Verified end-to-end withgraphify update .+graphify affectedon a toy project, not just direct extractor calls.Known limitation
Self-types on
traitbodies — this issue's own cake-pattern example — don't yet produce edges. Tracing the dispatch directly showedtrait_definitionisn't in_SCALA_CONFIG.class_types(onlyclass_definition/object_definitionare), so traits aren't class-like containers at all yet:parent_class_nidstaysNoneinside a trait body today (extends_clauseheritage is equally absent there, same cause). This dispatch is container-agnostic, so it will automatically cover trait self-types once trait recognition lands — already proposed separately in #1792 — no further change needed here.class/objectself-types already work today (tested below).Tests
New
tests/test_scala_self_type.py(8 tests, own fixture — avoids colliding with other open Scala PRs' shared-fixture edits): single type,with-compound, structural refinement (base type only, matching how refinement bodies are unscanned elsewhere), binder-onlyself =>(no edge), a plain class without a self-type (no spurious edge), coexistence with an unrelatedextends, edge shape (nocontext), and anaffected-traversal consumer test.Full suite identical on branch and bare
v8: same 6 pre-existing environment-dependent failures (missingopenaiextra, one wheel-build test) both sides, 8 net new passes. Ruff clean.