Skip to content
This repository was archived by the owner on Nov 10, 2025. It is now read-only.
This repository was archived by the owner on Nov 10, 2025. It is now read-only.

False positive if err variable is reused/redeclared #49

@kolyshkin

Description

@kolyshkin

I am seeing an false positive in the following code (example.go):

package main

import (
        "fmt"
        "io"
        "os"
)
  
func OsPipeFileReadReuseErrVar() {
        var buf [4096]byte
        r, _, err := os.Pipe()
        _, err = r.Read(buf[:])
        if err == io.EOF {
                fmt.Println(err)
        }
}

With the following added diagnostics:

diff --git a/errorlint/allowed.go b/errorlint/allowed.go
index d4274b8..faa0d61 100644
--- a/errorlint/allowed.go
+++ b/errorlint/allowed.go
@@ -126,6 +126,7 @@ func isAllowedErrorComparison(info *TypesInfoExt, binExpr *ast.BinaryExpr) bool
        // All assignments done must be allowed.
        for _, funcName := range functionNames {
                if !isAllowedErrAndFunc(errName, funcName) {
+                       fmt.Printf("err: %s fun: %s\n", errName, funcName)
                        return false
                }
        }

I get this result:

$ go build .
$ ./go-errorlint ./example.go 
err: io.EOF fun: os.Pipe
/home/kir/go/src/github.com/polyfloyd/go-errorlint/example.go:13:5: comparing with == will fail on wrapped errors. Use errors.Is to check for a specific error

So, the linter thinks err comes from os.Pipe while actually it is from (*os.File).Read.

NOTE this is not a regression in cd16050 (reproduced on both git tip as well as v1.4.3).

Metadata

Metadata

Assignees

No one assigned

    Labels

    wontfixThis will not be worked on

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions