Repository navigation
fix(go): a project package named like a standard-library package is not the standard library - #2368
Open
danusha2345 wants to merge 1 commit into
Open
danusha2345 wants to merge 1 commit into
danusha2345 wants to merge 1 commit into
Conversation
danusha2345
force-pushed
the
fix/go-stdlib-named-project-package
branch
from
October 6, 2026 09:21
4d03d6b to
4422389
Compare
danusha2345
pushed a commit
to danusha2345/codegraph
that referenced
this pull request
Oct 6, 2026
danusha2345
pushed a commit
to danusha2345/codegraph
that referenced
this pull request
Oct 6, 2026
…tdlib-named packages, colbymchenry#2373 daemon message) into fork main
danusha2345
force-pushed
the
fix/go-stdlib-named-project-package
branch
from
October 7, 2026 11:57
4422389 to
14ccd56
Compare
…ot the standard library
A call written through a package qualifier that matches a standard-library
package name (`errors.New`, `log.Infof`, `types.Policy{}`) was dropped as a
standard-library reference on the name alone, without looking at what the
file imports under that name. A project that has its own `lib/errors` or
`lib/log` lost nearly every call into them: on goharbor/harbor, 0 of 1,402
`errors.*` call sites and 1 of 1,325 `log.*` call sites written through the
project's packages had an edge.
The file's import now decides first: a qualifier imported, by its last path
segment or an alias, from a package of one of the project's own modules is a
project package. A file importing the real standard-library package, and a
name the file does not import at all, are handled as before.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
danusha2345
force-pushed
the
fix/go-stdlib-named-project-package
branch
from
October 7, 2026 16:04
14ccd56 to
07b426c
Compare
This branch has not been deployed
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.
Problem
A Go reference written through a package qualifier is dropped as a standard-library reference when the qualifier matches a name in the built-in list (
errors,log,types,user,url,token,parser, …). The check looks at the name alone, never at what the file imports under that name, so a project that has its own package with such a name loses nearly every call into it.The same happens to a composite literal (
errors.Error{…},types.Policy{…}), and to an import whose alias is the standard-library name (errors "example.com/app/lib/errors"). An alias with any other name (liberrors.New(…)) already resolved, as did the type reference in a signature (*errors.Error), which is indexed without its qualifier.Found on goharbor/harbor, where
src/lib/errorsandsrc/lib/logare used by most of the code base:callersoflib/errorsNewreturned 38 call sites, almost all of them inside the package itself, while 467errors.New(…)calls are written through the project's package.Fix
The file's import decides before the name does. A qualifier the file imports — by its last path segment, by the name #2410 assumes for an unaliased import (
…/log/v2→log), or by an alias — from a package of one of the project's own modules (the module lookup from #2361) is a project package, and the reference goes on to normal resolution, where the import already selects the package directory. Everything else is unchanged:errors/logis skipped as before;errors,token,url) is skipped as before;go.modis unchanged, since no import maps to a project module.One condition and a small helper in the resolver; no extraction change, so no re-parse is needed beyond the re-index the release already asks for.
Out of scope
func flush(ring *ringLog) { ring.Write(b) }) is still skipped. fix(go): type receivers from package-qualified parameters and call results; no guess for outside types #1954 handles that one in the adjacent condition. Rebased onto ed199e6, the two merge with a conflict inCHANGELOG.mdonly, their test suites pass together, and on harbor the merged tree gives exactly the sum of the two changes (25,538 → 28,537callsedges).var G = GetLogger,var Is = errors.Isin harbor) has no function node to link to, solog.G(ctx)anderrors.Is(…)still get no edge."example.com/app/lib/log/v2"is recognized asloghere with no further change. A test covers it, next to an outside module's…/errors/v2in the same file, which still gets no edge.Tests
New
__tests__/go-stdlib-named-package.test.ts(a real temp project with a rootgo.mod, real SQLite):errorspackage and a projectlogpackage resolves;liberrors "…/lib/errors"), and so does an alias that is the standard-library name itself, next to the standard library imported asstderrorsin the same file;"example.com/app/lib/log/v2", packagelog) resolves, anderrors.New(…)through an outside module'sgithub.com/acme/errors/v2in the same file gets no edge;errorsandloggets no edge, and a parameter namederrorsin a file with no such import does not reach the package's function.4 of the 7 fail on
mainat ed199e6 and all pass with the change, with the native kernel and withCODEGRAPH_KERNEL=0. The Go suites (go-*,goframe,rust-go-call-shape,gin-middleware-chain),resolution.test.tsand the neighbouring resolution suites pass in both modes.Measured on goharbor/harbor
src/at f25e9da (1,595 Go files, onego.mod), indexed from scratch withmainat ed199e6 and with this branch.mainindexes it identically run to run.callsinstantiatescontains)2,876 edges added (2,676
calls, 200instantiates), none removed and none retargeted. Every added edge was checked against the source: the line spells<qualifier>.<name>, and the file imports the target's directory under that qualifier.errors.*(lib/errors)log.*(lib/log)types.*(pkg/permission/types,pkg/quota/types)scanner.*,user.*,token.*,parser.*,url.*,trace.*errors.New(…)alone: 467 calls throughlib/errors, 0 linked before and 459 now; the 277 calls through the standard library'serrorshave no edge before or after. The 127 sites still without an edge are the package-level function values listed under "Out of scope" (log.G84,errors.As20,errors.Is14), onelog.WithField(…)for whichlib/loghas no package-level function in the index, and 8 package-levelvar ErrX = errors.New(…)initializers.Index time is unchanged within noise (five interleaved runs each: 6.6–8.3 s on
main, 6.8–7.6 s here). Two Go projects without such packages (100 and 52 Go files) produce byte-identical edge lists.🤖 Generated with Claude Code