diff --git a/gitnexus/src/core/ingestion/cfg/visitors/go-harvest.ts b/gitnexus/src/core/ingestion/cfg/visitors/go-harvest.ts index a5f17fec4..59e1a25f0 100644 --- a/gitnexus/src/core/ingestion/cfg/visitors/go-harvest.ts +++ b/gitnexus/src/core/ingestion/cfg/visitors/go-harvest.ts @@ -438,6 +438,18 @@ export class GoHarvester extends ScopeTreeHarvester { if (left) this.defLeftList(left, acc, op !== '='); return; } + case 'receive_statement': { + // `select { case v := <-ch: }` / `case v = <-ch:` — the left + // identifier(s) are DEFS of the channel-received value; `<-ch` (right) + // is a use of the channel. A bare `case <-ch:` has no left (uses only). + const left = node.childForFieldName('left'); + const right = node.childForFieldName('right'); + const isShort = node.children.some((c) => !c.isNamed && c.text === ':='); + if (isShort && left && right) this.registerListResultDefs(left, right); + if (right) this.walkValue(right, acc); + if (left) this.defLeftList(left, acc, false); + return; + } case 'inc_statement': case 'dec_statement': { // `x++` / `x--` — def AND use the lvalue when it's a plain identifier. diff --git a/gitnexus/test/unit/cfg/go-visitor.test.ts b/gitnexus/test/unit/cfg/go-visitor.test.ts index b05f23aa1..fcb6a4b74 100644 --- a/gitnexus/test/unit/cfg/go-visitor.test.ts +++ b/gitnexus/test/unit/cfg/go-visitor.test.ts @@ -407,6 +407,16 @@ describe('Go CfgVisitor — def/use harvest', () => { expect(hasUse(cfg, bindingIdx(cfg, 'k'))).toBe(true); void hasMayDef; // may-def path covered structurally by the conditional walk }); + + it('select receive `case v := <-ch` defines v, not a use-only (#2195 P2)', () => { + const cfg = go.cfgOf(pkg(`func f(ch chan int) { select { case v := <-ch: use(v) } }`)); + const v = bindingIdx(cfg, 'v'); + // the channel-received binding is a DEF (the channel-sourced value flows + // into v) — the bug recorded it as a use of an uninitialized var instead. + expect(hasDef(cfg, v)).toBe(true); + // and the channel `ch` is read. + expect(hasUse(cfg, bindingIdx(cfg, 'ch'))).toBe(true); + }); }); describe('Go CfgVisitor — functionStartColumn', () => {