You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ctxbackground precision: isContextBackgroundCall matches identifier name "context" syntactically while the same file detects the
[Content truncated due to length] #38789
The ctxbackground analyzer detects the context.Contextparameter of the enclosing function via package type-identity (correct), but detects the context.Background()call by comparing the bare identifier name to the string "context" (syntactic, no pass.TypesInfo). The two halves of the same linter use different rigor, which is both an internal inconsistency and a precision bug.
False positive: any local variable, field, or shadowing receiver named context with a Background() method (e.g. a custom context struct value) is matched. ident.Name == "context" does not verify the identifier resolves to the imported contextpackage.
False negative: an aliased import import ctxpkg "context" followed by ctxpkg.Background() is not matched, because the identifier name is ctxpkg, not context.
This mirrors the sortslice precision fix that landed in #38029, and the package-aware helper astutil.IsFmtErrorf. ctxbackground is unenforced (~30 candidate sites), so this is a safe, latent-only precision fix.
Recommendation
Resolve the selector's base identifier to the context package via the type system instead of by name, reusing the file's existing contextType(pass) import-scan pattern:
(Thread pass into the call site at the top of run.) Add testdata: a ctxpkg "context" aliased import (must flag) and a local context value with a Background() method (must not flag).
Validation checklist
Aliased import ctxpkg "context" + ctxpkg.Background() is now reported.
A non-package identifier named context with a Background() method is NOT reported.
Existing positive/negative testdata still pass.
go test ./pkg/linters/ctxbackground/... passes.
Effort: Small — single function signature + testdata; matches the landed #38029 template.
Activity
github-actions commentedon Jun 19, 2026
This issue was automatically closed because it expired on 2026-06-19T05:28:02.382Z.