Skip to content

fix(go): keep the receiver of methods on generic types - #812

Open
kunalgoesbyken wants to merge 1 commit into
trailhq:mainfrom
kunalgoesbyken:fix/go-generic-receiver-methods
Open

kunalgoesbyken wants to merge 1 commit into
trailhq:mainfrom
kunalgoesbyken:fix/go-generic-receiver-methods

Conversation

@kunalgoesbyken

Copy link
Copy Markdown
Contributor

Summary

A method on a generic type, func (s *Stack[T]) Push(x T), has a generic_type receiver that goReceiverType (extract.ts) and goReceiverTypeOf (bindings.ts) did not unwrap. The method was minted without an owner (Push, then Push~2 for the next generic type), calls on the receiver inside it were dropped, and var s Stack[int] or &Queue[K, V]{} bound nothing. No call into a generic type's methods resolved.

Changes

  • bindings.ts: goTypeName now also erases type arguments (*Stack[int] becomes Stack), and goReceiverTypeOf and the composite literal branch of handleGo use it.
  • extract.ts: goReceiverType unwraps generic_type after the pointer.

The method set belongs to the generic type, so every place that reads a Go type name erases the arguments.

$ graft callers Stack.Push      # before
Push · method · stack.go:L5-L5
  no indexed callers

$ graft callers Stack.Push      # after
Push · method · stack.go:L5-L5
  calls ← use (stack.go:L13-L18)
      15: s.Push(1)

Testing

On Windows 11 with Node 26:

  • test/graph-go-generics.test.ts (new): the methods keep their Stack and Queue owner and ids, the receiver call inside each resolves, and var s Stack[int], &Queue[string, int]{} and NewStack[int]() each resolve to their own type's Push and not the other's. Fails on main.
  • test/graph*, blast*, ask*, generic*, depth*, resolve* and covers* suites: 673 tests, 1 fail. The one failure is discoverWorkspaceChildren follows a symlinked child repo, a symlink permission error on Windows that fails the same way on main.
  • tsc --noEmit passes.

Fixes #811

`func (s *Stack[T]) Push` has a generic_type receiver, which the receiver
and type-name helpers did not unwrap. The method was minted without an
owner (`Push`, then `Push~2` for the next generic type), calls on the
receiver inside it were dropped, and `var s Stack[int]` or
`&Queue[K, V]{}` bound nothing, so no call into a generic type's methods
resolved.

Erase the type arguments wherever a Go type name is read: the receiver,
typed locals and fields, and composite literals.
@trailhq-graft

trailhq-graft Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

🌱 graft blast radius

Nothing outside this diff depends on it. 1 area changed; no indexed dependents at depth 2.
Tests: no test reaches Go Type Extraction.
Tag: @shhdwi — Go Type Extraction

Who knows this code — 1 person across 1 area
Area Who knows it
Go Type Extraction · changed @shhdwi — 7 commits, last 13d ago

Ownership is git history over each area's own files, weighted towards recent work (120-day half-life). Merge commits and bots are dropped, and you are dropped from your own PR. A name with no @ has no GitHub handle in its commit email — tag them by hand, or add a .mailmap entry. A suggestion from history, not a CODEOWNERS rule.

Test signal per changed area — 1 ✗

Reached = a node under a test path has a resolved edge into the changed symbol. It undercounts anything called indirectly — through a CLI, a spawned process or a dynamic import — so read a low ratio as “look here”, never as a coverage gate.

  • ✗ Go Type Extraction — 0 of 4 reached · no test file reaches it
    • not reached: goReceiverTypeOf, handleGo, goTypeName, goReceiverType

graft blast · origin/main...HEAD · depth 2 · 3 changed files

Open the interactive graph → — click an area to see its dependent symbols at file:line.

github-actions Bot added a commit that referenced this pull request Nov 10, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Go: methods on generic types lose their receiver, so callers Stack.Push finds nothing

1 participant