mirror of
https://github.com/colbymchenry/codegraph.git
synced 2026-10-26 04:19:33 +08:00
fix(scala): walk a val/var initializer scoped to the declared symbol (#693 for Scala)
The val/var hook minted the node and returned true, so the dispatcher only
scanned the subtree for function-as-value candidates and the initializer's
code was never walked:
val fieldLambda: () => Unit = () => target() // no caller
val direct = target() // no caller
lazy val lazily = compute() // no caller
val anon = new Runnable { def run() = target() } // no caller
Scala puts almost everything in a val, so this is not an edge case: on a
32-file SpinalHDL project the graph was missing 812 references.
Fix: walk the `value` field through visitFunctionBody with the declared symbol
pushed on the scope stack — the same shape as Go's #693/#744 fix, which the
grammar supports directly here (`val_definition` exposes `value`).
Kernel and TS extractor move together; kernel parity holds.
Measured on that SpinalHDL project: 0 lost refs, 0 re-attributed, +812 new,
node and edge counts unchanged (824/792), 32/32 files byte-parity between the
two arms.
This commit is contained in:
@@ -166,6 +166,16 @@ export const scalaExtractor: LanguageExtractor = {
|
||||
|
||||
const created = ctx.createNode(kind, name, node, { signature: sig, visibility: extractVisibility(node) });
|
||||
if (created && typeNode) emitScalaTypeRefs(typeNode, created.id, ctx, ctx.source);
|
||||
// Walk the initializer ATTRIBUTED to the declared symbol (#693, the Go
|
||||
// fix): the hook consumes this subtree and the dispatcher only scans it
|
||||
// for function-as-value candidates, so `val cb = () => target()` — and
|
||||
// even a plain `val x = compute()` — emitted no call edge at all.
|
||||
const valueNode = node.childForFieldName('value');
|
||||
if (created && valueNode) {
|
||||
ctx.pushScope(created.id);
|
||||
ctx.visitFunctionBody(valueNode, created.id);
|
||||
ctx.popScope();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user