Skip to content

nilctxpassed isBuiltinNil still lacks ParenExpr unwrap (issue 63343 auto-expired, 3rd occurrence) #65227

Description

@github-actions

Lineage: #61519 (filed R69) -> #63343 (R77 refile, auto-expired closed/not_planned on 2026-10-02) -> this issue (R85 refile). Third time this exact bug has been filed with zero code change in between.

Bug

isBuiltinNil (pkg/linters/nilctxpassed/nilctxpassed.go:124-135) performs a bare type assertion with no ParenExpr unwrap first:

func isBuiltinNil(pass *analysis.Pass, expr ast.Expr) bool {
	ident, ok := expr.(*ast.Ident)
	if !ok || ident.Name != "nil" {
		return false
	}
	...
}

A parenthesized nil literal passed as a context.Context argument, e.g. doSomething((nil)), is legal (if unusual) Go and is completely invisible to this linter since (nil) is an *ast.ParenExpr, not an *ast.Ident, and the assertion fails before TypesInfo is ever consulted.

Re-verified 2026-10-03: nilctxpassed.go:124-135 unchanged; zero occurrences of UnwrapParenExpr anywhere in the file.

CI enforcement: .github/workflows/cgo.yml LINTER_FLAGS include -nilctxpassed on both the native and wasm custom-linter steps with -test=false.

Live impact: no production false negative found (grepped for parenthesized nil-literal arguments in context-typed call positions across pkg/, none found) -- latent but genuinely untested, zero ParenExpr coverage in testdata.

Pattern class: paren_unwrap_gap -- the same recurring class already fixed via astutil.UnwrapParenExpr in walkfuncerrshadow.go, mapdeletecheck.go, and packagelevelmutableslicemap.go, and via astutil.TwoValueTypeAssertionOKIdent in typeassertionokdiscarded.go.

Recommendation

Wrap expr with astutil.UnwrapParenExpr(expr) before the *ast.Ident assertion in isBuiltinNil, matching the established fix idiom used elsewhere in this codebase.

Validation checklist

  • Add a testdata case doSomething((nil)) (parenthesized nil as a context.Context argument) expecting a diagnostic
  • Confirm existing non-paren nil and non-nil testdata cases are unaffected

Effort: trivial -- one-line unwrap plus one testdata case.

Generated by 🤖 Sergo - Serena Go Expert · claude · agent · 317.8 AIC · ⌖ 7.26 AIC · ⊞ 5.3K · ◷

  • expires on Oct 9, 2026, 8:11 PM UTC-08:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    cookieIssue Monster Loves Cookies!sergo

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions