Summary
rawloginlib decides whether a call targets the standard log package by comparing the receiver identifier's name to the literal string "log", with no type resolution. This produces both a false positive (a local/parameter/field named log bound to a custom logger) and a false negative (an aliased import of log). Because rawloginlib is CI-enforced (.github/workflows/cgo.yml:1123 LINTER_FLAGS), the false positive is a build-blocker.
This is the same precision class already fixed for sortslice (#38029, merged) and still open for regexpcompileinfunction (#39733) and ctxbackground (#38789).
Location
pkg/linters/rawloginlib/rawloginlib.go:62
ident, ok := sel.X.(*ast.Ident)
if !ok {
return
}
if ident.Name == "log" && rawLogFuncs[sel.Sel.Name] { // <-- syntactic name match, no TypesInfo
False positive (build-blocking)
log is one of the most common local-variable / parameter names for a logger. A custom logger that shadows the package name is wrongly flagged:
func handle(log *logger.Logger) {
log.Printf("...") // custom logger — NOT stdlib log, but ident.Name == "log" => reported
}
Since the linter runs in CI enforcement, this fails the build on legitimate code.
False negative
An aliased import escapes detection entirely, defeating the enforcement the linter exists to provide:
import applog "log"
func f() { applog.Fatal("boom") } // ident.Name == "applog" => not reported
Recommended fix
Resolve package identity through the type system, mirroring the existing canonical helper astutil.IsFmtErrorf (pkg/linters/internal/astutil/astutil.go:64-72):
obj := pass.TypesInfo.ObjectOf(ident)
pkgName, ok := obj.(*types.PkgName)
if ok && pkgName.Imported().Path() == "log" && rawLogFuncs[sel.Sel.Name] { ... }
Note that osexitinlibrary (osexitinlibrary.go:59, ident.Name == "os") and fprintlnsprintf (fprintlnsprintf.go:144, ident.Name == "fmt") share the identical syntactic gap. Consider extracting a shared astutil.IsStdPkgSelector(pass, sel, pkgPath) helper and reusing it across all three to fix the class once.
Validation checklist
Effort
Small — single-file change, or single-file plus an optional shared astutil helper that also closes osexitinlibrary and fprintlnsprintf.
Generated by 🤖 Sergo - Serena Go Expert · ◷
Summary
rawloginlibdecides whether a call targets the standardlogpackage by comparing the receiver identifier's name to the literal string"log", with no type resolution. This produces both a false positive (a local/parameter/field namedlogbound to a custom logger) and a false negative (an aliased import oflog). Becauserawloginlibis CI-enforced (.github/workflows/cgo.yml:1123LINTER_FLAGS), the false positive is a build-blocker.This is the same precision class already fixed for
sortslice(#38029, merged) and still open forregexpcompileinfunction(#39733) andctxbackground(#38789).Location
pkg/linters/rawloginlib/rawloginlib.go:62False positive (build-blocking)
logis one of the most common local-variable / parameter names for a logger. A custom logger that shadows the package name is wrongly flagged:Since the linter runs in CI enforcement, this fails the build on legitimate code.
False negative
An aliased import escapes detection entirely, defeating the enforcement the linter exists to provide:
Recommended fix
Resolve package identity through the type system, mirroring the existing canonical helper
astutil.IsFmtErrorf(pkg/linters/internal/astutil/astutil.go:64-72):Note that
osexitinlibrary(osexitinlibrary.go:59,ident.Name == "os") andfprintlnsprintf(fprintlnsprintf.go:144,ident.Name == "fmt") share the identical syntactic gap. Consider extracting a sharedastutil.IsStdPkgSelector(pass, sel, pkgPath)helper and reusing it across all three to fix the class once.Validation checklist
logof a non-logtype callinglog.Printf→ no diagnostic.import applog "log"thenapplog.Fatal(...)→ diagnostic reported.log.Printfin apkg/package still reported.go test ./pkg/linters/rawloginlib/...green.Effort
Small — single-file change, or single-file plus an optional shared
astutilhelper that also closesosexitinlibraryandfprintlnsprintf.