Repository navigation
fix(go): a type in a signature or composite literal links a type, never a method of its name - #2416
Merged
Merged
Conversation
…er a method of its name
A Go type position -- a parameter or result type, a composite literal's
type -- names a type of the package Go reads it from. Name matching (and
the instance-method guess, and the Express resolver reading Go refs) took
whatever declaration shared the name: etcd's
`func (ti *treeIndex) KeyIndex(keyi *keyIndex) *keyIndex` linked both types
to the method `treeIndex.keyIndex`, prometheus's `samples{...}` literals to
`sampleRing.samples`, and `semver.Version` or `config.URL{...}` from
outside packages to project methods and functions of that name.
gateTargetKind now hands every Go type position to goTypePositionTarget:
a method or function target moves to the type of that name in the
reference's own package (bare) or the imported project package (`pkg.T`),
or is dropped when there is none; a bare name that found another
package's type moves to its own package's type when it declares one
(prometheus's `prompb` builds its own `Histogram_CountInt`). A generic
method's receiver (`func (p *Pool[T]) Get() T`) now declares type
parameters for gateTypeParameter.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`semver.Version` reads as an outside package since #2410, so its links to project methods are gone before this change; `config.URL{...}` still went to `scrape.Target.URL`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 7, 2026
This was referenced Oct 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A Go type position now resolves only to a type (
struct/interface/type_alias) of the package Go reads the name from. A type position here is a parameter or result type (areferencesref from a function or method) or a composite literal's type (instantiates). Route handlers arereferencesrefs too, but they are values, so they are left alone.gateTargetKind(src/resolution/index.ts) hands every Go type position to a newgoTypePositionTarget(src/resolution/name-matcher.ts, beside the other Go scoping helpers). So the gate applies to whatever strategy won: name matching, the instance-method single-candidate guess, or a framework resolver (before fix(frameworks): a framework resolves only references written in its own languages #2415, Express took etcd's*zap.Loggerresults forEtcdServer.Logger).pkg.T, or the dotted name a composite literal keeps).unresolved_refs._, so prometheus'sprompb/codec.gohad builtwrite/v2'sHistogram_CountInt.declaredTypeParameters(src/resolution/type-parameters.ts) now reads a Go method's receiver.Tinfunc (p *Pool[T]) Get() Tis the receiver's type parameter; prometheus linked it to the methodSample.Tin another package.&keyIndex{…}linkedtreeIndex.keyIndex, prometheus's 43samples{…}linkedsampleRing.samples, and 20config.URL{…}(prometheus/common, an outside package) linkedscrape.Target.URL.Validation
Test first.
__tests__/go-type-position-kinds.test.tsputs the shapes below in miniature.ti.keyIndex(keyi)call still links the method.tsc --noEmitis clean.A/B on real repos. Main 9d07864 (the commit before this squash) vs this branch, a full
init -yper arm on the native-kernel path, diffed per reference site (source, line, col, refName):references/instantiatesedges differ.*zap.Loggerlinks the Express resolver made, which fix(frameworks): a framework resolves only references written in its own languages #2415 now prevents at the source. On the base before fix(go): an unaliased import is also known by the name goimports assumes for its package #2410 (31c3328, and dd70646 before that, on both extraction paths), the retargets were the same. etcd also dropped 80 more links there:semver.Version,raft.*andprotoreflect.*types landing on project methods and functions. fix(go): an unaliased import is also known by the name goimports assumes for its package #2410 now prevents those upstream by reading the goimports package names and a comment-free import header.Every changed site, triaged:
keyIndex×12 parameter/result types and ×5&keyIndex{…}→ structkeyIndex(weretreeIndex.keyIndex);kvsToEvents(…, c contains, …)→ interfacecontains(was its own method spec);*leafPageElement→ struct (waspage.leafPageElement).samples{…}×43 → defined typesamplesinstorage/series.go(were the methodsampleRing.samples);floatBucketIterator×2 → struct;isHistogram_Count/isHistogram_ZeroCount×4 → the interfaces (were methods of the oneof structs);(ec2Client, error)→ interfaceec2Client;AppenderV2→ interface (wasfanout.AppenderV2);&Histogram_CountInt{…}and its 3 siblings inprompb/codec.go→prompb's own structs (werewrite/v2's).config_util.URL{…}×10,common_config.URL{…}×8 andconfig.URL{…}×2, allgithub.com/prometheus/common/config→ werescrape.Target.URL;T×4 in the generic receivers ofutil/zeropool,web/api/testhelpersandweb/api/v1→ wereSample.T.After the fix, both measuring scripts report 0 on all three repos: no type position on a method or function, and no composite literal on a non-type.
Tests on the merged tree (Go suites, #2410's
go-import-package-names,kernel-tsjs-parity,sync,sync-import-retry,resolution,frameworks,cross-file-visibility,reference-target-kind,type-parameter-refs): 20 files, 653 tests, all pass.Full suite (Windows, other sessions holding the CPU at 90–100%):
EBUSYon temp-dir cleanup, or a wall-clock assertion.EBUSY, timeouts).Not changed here
=aliases are not indexed. A bareEventin etcd'sclient/v3(type Event = mvccpb.Event), orPrometheusVersion/Typein prometheus, keeps linking another package's type. The own package declares no type of that name, and for an alias that target is often the right one.🤖 Generated with Claude Code