errcheck icon indicating copy to clipboard operation
errcheck copied to clipboard

errcheck throws unwarranted error

Open Maxrovr opened this issue 3 years ago • 7 comments

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:

  1. Install golang >v1.17
  2. write code to use any of the constants in the math package (ex: MaxInt64]
  3. 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?

Maxrovr avatar Feb 12 '22 02:02 Maxrovr

Could you please post a link to a minimal package that reproduces this error when running errcheck?

kisielk avatar Feb 12 '22 02:02 kisielk

package main

import (
	"fmt"
	"math"
)

func main() {
	fmt.Println("Hello ", math.MaxInt64)
}

running errcheck on this will reproduce the error

Maxrovr avatar Feb 13 '22 17:02 Maxrovr

I could not reproduce this with golang 1.17.5 🤔

dtcaciuc avatar Feb 14 '22 03:02 dtcaciuc

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

Maxrovr avatar Feb 14 '22 17:02 Maxrovr

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

dtcaciuc avatar Feb 15 '22 01:02 dtcaciuc

@Maxrovr ping

dtcaciuc avatar Mar 26 '22 03:03 dtcaciuc

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

Maxrovr avatar Mar 30 '22 21:03 Maxrovr