errcheck
errcheck copied to clipboard
errcheck throws unwarranted error
golang version: >1.17
The following error occurs when running errcheck:
error: failed to check packages: errors while loading package github.com/********-********/****************: [/Users/********/projects/go/src/github.com/********/********/********/********.go:line:col: MaxInt64 not declared by package math]
To reproduce:
- Install golang >v1.17
- write code to use any of the constants in the math package (ex: MaxInt64]
- Run the errcheck
Clearly when I drill down into the go library, I see the const.go file under the math package and also see the MaxInt64 const declared. Why would this error still show up?
Could you please post a link to a minimal package that reproduces this error when running errcheck?
package main
import (
"fmt"
"math"
)
func main() {
fmt.Println("Hello ", math.MaxInt64)
}
running errcheck on this will reproduce the error
I could not reproduce this with golang 1.17.5 🤔
I tried 1.17 and 1.17.2 and they both errored. Here is my console output.
rasiddan@rasiddan-mac main % errcheck
error: failed to check packages: errors while loading package _/Users/rasiddan/sandbox/go/main: [/Users/rasiddan/sandbox/go/main/main.go:9:29: MaxInt64 not declared by package math]
rasiddan@rasiddan-mac main % go version
go version go1.17.2 darwin/amd64
Ran it on 1.17.5 as well, saw the same error.
running on MacOS Big Sur (confirmed same errors from catalina users as well). Also have -mod=vendor and go111module=on
I originally tried it on Windows11/WSL, but now I also tried it on MacOS Catalina and I still can't reproduce the issue.
It's a wild guess, but could that MaxInt64 text in your file contain a unicode char that looks like an ASCII one? For instance, I was able to reproduce your error by substituting "a" with its first lookalike from this page https://gist.github.com/StevenACoffman/a5f6f682d94e38ed804182dc2693ed4b
@Maxrovr ping
I tried this, but it was not the case, I have stopped using the const in my code for now and directly using the const value. Will investigate once I am able to