Repository navigation
Description
Summary
Any type referenced by a dotted, package-qualified name — cats.data.EitherT, cats.effect.IO,
cats.effect.IOApp — parses to a distinct stable_type_identifier node, which neither the type-reference
walker (_scala_collect_type_refs) nor the extends_clause base-detection code recognizes. The unqualified
form of the same name (EitherT, IO, IOApp) already works correctly everywhere. This one root cause has
three separate, verified manifestations: a qualified generic base is silently dropped from references
edges, a bare qualified type used as a type argument is silently dropped too, and — most severe — a qualified
extends base either loses its inherits edge entirely or (if it has type arguments) produces one to a
wrongly-keyed node that can never unify with the real class/object it points to.
Manifestation 1 & 2: qualified types are silently dropped from references edges
Isolated from an unrelated, separately-filed gap about file-scope (top-level) definitions losing
parent_class_nid entirely, by nesting inside a real class here so parent_class_nid is genuinely present:
class Holder:
val stack: cats.data.EitherT[cats.effect.IO, String, Int] = nullRunning this through the actual installed extractor
(graphify.extractors.engine._extract_generic + graphify.extract._SCALA_CONFIG, called directly):
NODE Holder
NODE String
NODE Int
EDGE <file> -[contains]-> Holder
EDGE Holder -[references]-> String (generic_arg)
EDGE Holder -[references]-> Int (generic_arg)
String/Int (the plain generic arguments) resolve correctly. EitherT (the generic base) and IO (a
qualified type argument with no generics of its own) are both completely absent — not a single edge or
node for either.
generic_type
stable_type_identifier <- base: "cats.data.EitherT" — the qualified generic base
type_arguments
stable_type_identifier <- "cats.effect.IO" — bare qualified type argument
type_identifier "String"
type_identifier "A"
_scala_collect_type_refs's generic_type handling only accepts a bare type_identifier as the base:
if t == "generic_type":
base = node.child_by_field_name("type")
if base is None:
for c in node.children:
if c.type == "type_identifier":
base = c
break
if base is not None and base.type == "type_identifier":
text = _read_text(base, source)
if text:
out.append((text, "generic_arg" if generic else "type"))base.type == "type_identifier" is False for stable_type_identifier, so the whole block is skipped —
EitherT never gets appended. Separately, IO (passed in as a plain type-argument entry, recursively) hits
the function's top-level dispatch:
def _scala_collect_type_refs(node, source: bytes, generic: bool, out: list[tuple[str, str]]) -> None:
if node is None:
return
t = node.type
if t == "type_identifier": ...
if t == "generic_type": ...
if t in ("compound_type", "infix_type", "function_type", "tuple_type",
"annotated_type", "projected_type"): ...stable_type_identifier matches none of these ifs, so the function falls straight through and returns
without appending anything for IO.
Isolating the qualified type's name — same .is_named filtering technique as the self-type fix in
cats.data.EitherTstable_type_identifier
stable_identifier "cats.data"
type_identifier "EitherT"
pkg.OtherTraitstable_type_identifier
identifier "pkg"
type_identifier "OtherTrait"
No field names on either child (field_name_for_child returns None for both, checked directly) — but the
actual type name is reliably the last named child regardless of whether the qualifying prefix is a single
identifier (2-segment name) or a nested stable_identifier (3+-segment name). Using tree-sitter's own
named_child/named_child_count rather than building a Python list of children just to index the last
element:
def _tail_type_name(node):
if node.named_child_count == 0:
return None
tail = node.named_child(node.named_child_count - 1)
return tail if tail.type == "type_identifier" else NoneProposed diff — _scala_collect_type_refs
def _scala_collect_type_refs(node, source: bytes, generic: bool, out: list[tuple[str, str]]) -> None:
if node is None:
return
t = node.type
if t == "type_identifier":
text = _read_text(node, source)
if text:
out.append((text, "generic_arg" if generic else "type"))
return
if t == "stable_type_identifier":
tail = _tail_type_name(node)
if tail is not None:
text = _read_text(tail, source)
if text:
out.append((text, "generic_arg" if generic else "type"))
return
if t == "generic_type":
base = node.child_by_field_name("type")
if base is None:
for c in node.children:
if c.type == "type_identifier":
base = c
break
if base is not None and base.type == "type_identifier":
text = _read_text(base, source)
if text:
out.append((text, "generic_arg" if generic else "type"))
elif base is not None and base.type == "stable_type_identifier":
tail = _tail_type_name(base)
if tail is not None:
text = _read_text(tail, source)
if text:
out.append((text, "generic_arg" if generic else "type"))
for c in node.children:
if c.type == "type_arguments":
for arg in c.children:
if arg.is_named:
_scala_collect_type_refs(arg, source, True, out)
return
if t in ("compound_type", "infix_type", "function_type", "tuple_type",
"annotated_type", "projected_type"):
for c in node.children:
if c.is_named:
_scala_collect_type_refs(c, source, generic, out)Verified against the real parsed node: running this exact logic against Holder's stack type resolves
[('EitherT', 'type'), ('IO', 'generic_arg'), ('String', 'generic_arg'), ('Int', 'generic_arg')] — all four,
where only String/Int resolved before.
Regression-tested against every fixture already verified in
graphify#2049 and
graphify#2052, since this function is shared by
both proposals — byte-identical results to what's already published, in every case:
Elem -> [('X','type'), ('String','type'), ('Char','type'), ('Array','type'), ('t','generic_arg'), ('t','type')]
Id -> [('Long', 'type')]
Alias -> [('List', 'type'), ('Int', 'generic_arg')]
Foo -> [] (abstract member, no "type" field — unchanged)
Bar -> [] (abstract member, "bound" field only — unchanged)
Baz -> [] (same)
selftype1 (Logging with Database) -> [('Logging', 'type'), ('Database', 'type')]
selftype2 (HasConfig) -> [('HasConfig', 'type')]
selftype_refinement (Logging {...}) -> [('Logging', 'type')]
selftype3 / Outer (self =>, no type) -> [] (unchanged)
Manifestation 3: qualified extends bases — one sub-case loses the edge, the other gets a wrongly-keyed one
class Foo extends cats.effect.IOAppReal extractor output: only the file and Foo nodes — zero inherits edge. The extends_clause scan
only recognizes two child types:
if config.ts_module == "tree_sitter_scala":
extend = node.child_by_field_name("extend")
if extend is None:
for c in node.children:
if c.type == "extends_clause":
extend = c
break
if extend is not None:
bases: list[tuple[str, int]] = []
for c in extend.children:
if c.type == "type_identifier":
bases.append((_read_text(c, source), c.start_point[0] + 1))
elif c.type == "generic_type":
base = c.child_by_field_name("type")
if base is None:
for sc in c.children:
if sc.type == "type_identifier":
base = sc
break
if base is not None:
bases.append((_read_text(base, source), c.start_point[0] + 1))A bare qualified base parses to extends_clause > stable_type_identifier directly — matching neither
type_identifier nor generic_type — so the entire base is skipped, bases stays empty, no inherits edge
at all.
class Foo extends cats.effect.SomeGeneric[Int]Real extractor output here is different and more subtle: it does produce an inherits edge, but to a
node keyed cats_effect_somegeneric, labeled "cats.effect.SomeGeneric" — the entire dotted string as one
opaque name. The generic_type branch above has no base.type == "type_identifier" guard (unlike
_scala_collect_type_refs's version) — it calls _read_text(base, source) on whatever base is, so a
stable_type_identifier base gets its full qualified text read verbatim. This node would never unify with a
real SomeGeneric class/object declared elsewhere (whose id is derived from just SomeGeneric), silently
producing an orphaned stub instead of a correct inherits edge.
Proposed diff — extends_clause
for c in extend.children:
if c.type == "type_identifier":
bases.append((_read_text(c, source), c.start_point[0] + 1))
elif c.type == "stable_type_identifier":
tail = _tail_type_name(c)
if tail is not None:
bases.append((_read_text(tail, source), c.start_point[0] + 1))
elif c.type == "generic_type":
base = c.child_by_field_name("type")
if base is None:
for sc in c.children:
if sc.type == "type_identifier":
base = sc
break
if base is not None and base.type == "stable_type_identifier":
tail = _tail_type_name(base)
if tail is not None:
base = tail
if base is not None:
bases.append((_read_text(base, source), c.start_point[0] + 1))Verified against real parsed nodes — running this exact logic:
class Foo extends cats.effect.IOApp -> bases = ['IOApp']
class Foo extends cats.effect.SomeGeneric[Int] -> bases = ['SomeGeneric']
Both now resolve to the bare type name, matching how a locally-declared IOApp/SomeGeneric would already
be keyed.
Checked inherits/mixes_in ordering isn't disturbed by mixing qualified and unqualified bases in one
with-chain — a realistic shape (a cats-effect app's IOApp base plus local traits):
class Foo extends cats.effect.IOApp with SomeTrait with pkg.OtherTraitbases = ['IOApp', 'SomeTrait', 'OtherTrait']
inherits -> IOApp
mixes_in -> SomeTrait
mixes_in -> OtherTrait
First base is still inherits regardless of qualification, subsequent ones still mixes_in, correctly.
Regression-tested against the unqualified extends fixture from
graphify#2052
(trait UserService extends Base: self: Logging => ...) — bases = ['Base'], unchanged.
What this deliberately does not propose
- Cross-file resolution —
ensure_named_node's qualified-then-bare fallback (used by every reference in this
extractor) is unaffected by this proposal; this only fixes extracting the name itself from a qualified
reference, not how far that name is then resolved. - Any change to how the qualifying package/object prefix (
cats.data,pkg) itself is represented — it's
discarded entirely, same as the already-accepted precedent in
graphify#2048 (export pkg.helper.{util}also
keeps only the tail segment). - Any interaction with the separately-filed top-level (file-scope)
parent_class_nidgap — every fixture
here was deliberately nested inside a real class to isolate this finding from that one.
Environment
- graphifyy 0.9.20, tree_sitter_scala 0.26.0
- All shapes were dumped directly against the installed grammar, checked for absence of
ERROR/is_missing
nodes. The current (pre-fix) behavior for manifestations 1/2 and theextends_clausecases was confirmed
by running the real, installedgraphify.extractors.engine._extract_genericend-to-end extractor (imported
and called directly, not reimplemented) — that part is the actual shipped behavior, not a simulation. The
proposed fixes — which don't exist in the installed package yet — were verified by applying the exact
same patch shown above to a local copy of_scala_collect_type_refs/theextends_clauseloop and running
it against the same real parsed nodes (tree_sitter_scalaoutput, not hand-written trees), then
regression-tested against every fixture previously verified in
graphify#2049 and
graphify#2052 with byte-identical results.
Activity
sub4biz commentedon Nov 15, 2026
Retested the original examples on clean upstream v0.9.109. A qualified
extendsbase is now covered by the corresponding regression test, but the qualified generic reference case remains: forcats.data.EitherT[cats.effect.IO, String, Int]insideHolder, the extracted reference targets includeStringandInt, but notEitherTorIO. The issue should remain open for the reference-walker case.