Skip to content

uncheckedflushreturn: ExprStmt and AssignStmt branches do not unwrap ParenExpr, parenthesized Flush() escapes detection #71810

Done

Description

@github-actions

Linter: uncheckedflushreturn (pkg/linters/uncheckedflushreturn/uncheckedflushreturn.go), CI-enforced native+wasm (cgo.yml LINTER_FLAGS, both jobs).

Problem: Two of the three node-filter branches do a bare type assertion to *ast.CallExpr with no astutil.UnwrapParenExpr call first, and the file does not import astutil at all:

  • checkDiscardedFlushExpr (line 58): call, ok := stmt.X.(*ast.CallExpr)
  • checkDiscardedFlushAssign (line 78): call, ok := assign.Rhs[0].(*ast.CallExpr)

Only the third branch, checkDiscardedFlushDefer, is structurally immune since DeferStmt.Call is always a concrete *ast.CallExpr by Go grammar.

Impact: A parenthesized discard such as (bw.Flush()) as a bare statement, or _ = (bw.Flush()), silently escapes this CI-enforced linter, since Go allows a CallExpr to be wrapped in ParenExpr without changing its meaning. This is the same recurring paren_unwrap_gap class already fixed in several sibling linters (closeerrorunchecked, typeassertionnil, and the ExprStmt/AssignStmt dual-branch fix previously applied to astutil.MatchDiscardedErrorCall and pkg/linters/internal/resourcetracker.go).

Evidence: testdata/src/uncheckedflushreturn/uncheckedflushreturn.go has zero parenthesized-call test cases (bad/badBlankAssign/deferBad/good/suppressed/deferSuppressed all use bare unparenthesized calls).

Recommendation: Call astutil.UnwrapParenExpr on stmt.X and assign.Rhs[0] before the type assertion in both branches, matching the reference pattern already used elsewhere (e.g. uncheckedsliceindex.go, mapdeletecheck.go). Add parenthesized-call test cases to testdata for both branches.

Validation checklist:

  • Add (bw.Flush()) as a bare ExprStmt test case, expect diagnostic
  • Add _ = (bw.Flush()) test case, expect diagnostic
  • Existing bad/good/suppressed cases still pass unchanged

Effort: Small (2-line fix plus 2 testdata cases, isolated to one file).

Generated by 🤖 Sergo - Serena Go Expert · claude · agent · ~203 AIC · ⌖ ~1 AIC · ⊞ 4.1K · ◷

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

Metadata

Metadata

Labels

cookiesergo

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions