Files
codegraph/__tests__
Colby Mchenry 90d6501b09 fix(go): a call of a standard method name like err.Error() links to its receiver's declared type, never to one it shares a word with (#2664)
A Go call of a standard method name (GO_STD_METHODS: Error, String, Err,
Lock, Len, Header, ...) on a receiver whose type wasn't worked out was
guessed by a word the receiver shares with a type's name: kubernetes'
`err.Error()` linked to `notRegisteredErr::Error`, prometheus's to
`ParseErr::Error`, etcd's `leaderID.String()` to `MoveLeaderRequest`, and
a receiver declared as a type from outside the project to a project type
of its name (etcd's `var pendingMu sync.Mutex` to its concurrency `Mutex`).

In matchMethodCall, for a standard method name on a plain Go variable:
- The receiver's declaration in scope (goLocalDecl, the scope reader)
  decides, over the unscoped pattern scan: a project type's own method,
  through the package that declares it; nothing for a predeclared type, a
  type from outside the project, a type literal, a value an outside
  package hands out, or a declared type that lacks the method.
- Otherwise a guess needs the receiver to name the owner type itself,
  case and a trailing number aside (`id` an `ID`, `urlsMap` a `URLsMap`):
  in Strategy 3 through receiverNamesOwner, and in Strategy 2, which took
  any method of the owner's file whose name contained the type's
  (`status` reached `RuntimeStatus::String` beside a `Status` type).
- Only a declaration the scope reader finds rules a call out. The pattern
  scan reads back for the name without block scope and can find another
  declaration of it, like a test table's `version string` above
  `version, _ := parse(...)`; valid Go calls no method but `Error` on a
  predeclared type, so such a read says nothing.

A/B on main b4e10138, same kernel for both arms, full index per arm:
- gin: 17 guesses dropped; 14 calls newly typed (`c.String(...)` in
  `func(c *gin.Context)` handlers).
- prometheus: 265 dropped, 89 newly typed, 6 retargeted.
- etcd: 335 dropped (23 of them typed links of `sync.Mutex` and
  `sync.RWMutex` values to project namesakes), 52 newly typed, 7
  retargeted.
- harbor: 174 dropped, 6 newly typed, 6 retargeted.
- kubernetes: 2489 dropped, 241 newly typed, 77 retargeted.
No link of any other method name changed, and the fmt, llmc and typeorm
controls are identical. Of 132 dropped links sampled, 3 were right
(locals typed by a project call's result, which no reader types yet).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 15:51:16 +00:00
..