Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typecheck errors in the source of golang code #3649

Closed
4 tasks done
PanKaker opened this issue Mar 3, 2023 · 11 comments
Closed
4 tasks done

Typecheck errors in the source of golang code #3649

PanKaker opened this issue Mar 3, 2023 · 11 comments
Labels
question Further information is requested

Comments

@PanKaker
Copy link

PanKaker commented Mar 3, 2023

Welcome

  • Yes, I'm using a binary release within 2 latest major releases. Only such installations are supported.
  • Yes, I've searched similar issues on GitHub and didn't find any.
  • Yes, I've included all information below (version, config, etc.).
  • Yes, I've tried with the standalone linter if available (e.g., gocritic, go vet, etc.). (https://golangci-lint.run/usage/linters/)

Description of the problem

Typecheck errors occurred when try to run command in my project dir:

cat ./go.mod
module test
go 1.20

golangci-lint run ./...

../../../opt/go/1.20.1/src/runtime/debuglog.go:296:20: StringData not declared by package unsafe (typecheck)
        strData := unsafe.StringData(x)
                          ^
../../../opt/go/1.20.1/src/runtime/heapdump.go:159:37: StringData not declared by package unsafe (typecheck)
        dumpmemrange(unsafe.Pointer(unsafe.StringData(s)), uintptr(len(s)))
                                           ^
../../../opt/go/1.20.1/src/runtime/heapdump.go:202:32: StringData not declared by package unsafe (typecheck)
                dwrite(unsafe.Pointer(unsafe.StringData(pkgpath)), uintptr(len(pkgpath)))
                                             ^
../../../opt/go/1.20.1/src/runtime/proc.go:658:16: String not declared by package unsafe (typecheck)
                        s := unsafe.String(p, findnull(p))
                                    ^
../../../opt/go/1.20.1/src/runtime/string.go:105:17: String not declared by package unsafe (typecheck)
                return unsafe.String((*byte)(p), 1)
                              ^
../../../opt/go/1.20.1/src/runtime/string.go:115:16: String not declared by package unsafe (typecheck)
        return unsafe.String((*byte)(p), n)
                      ^
../../../opt/go/1.20.1/src/internal/fmtsort/sort.go:182:1: missing return (typecheck)
}
^
../../../opt/go/1.20.1/src/io/pipe.go:22:4: a.Lock undefined (type *onceError has no field or method Lock) (typecheck)
        a.Lock()
          ^
../../../opt/go/1.20.1/src/io/pipe.go:23:10: a.Unlock undefined (type *onceError has no field or method Unlock) (typecheck)
        defer a.Unlock()
                ^
../../../opt/go/1.20.1/src/io/pipe.go:30:4: a.Lock undefined (type *onceError has no field or method Lock) (typecheck)
        a.Lock()
          ^
../../../opt/go/1.20.1/src/io/pipe.go:31:10: a.Unlock undefined (type *onceError has no field or method Unlock) (typecheck)
        defer a.Unlock()
                ^
../../../opt/go/1.20.1/src/os/file_unix.go:416:15: invalid operation: cannot compare d.info != nil (operator != not defined on untyped nil) (typecheck)
        if d.info != nil {
                     ^
../../../opt/go/1.20.1/src/syscall/syscall_unix.go:63:4: m.Lock undefined (type *mmapper has no field or method Lock) (typecheck)
        m.Lock()
          ^
../../../opt/go/1.20.1/src/syscall/syscall_unix.go:64:10: m.Unlock undefined (type *mmapper has no field or method Unlock) (typecheck)
        defer m.Unlock()
                ^
../../../opt/go/1.20.1/src/syscall/syscall_unix.go:76:4: m.Lock undefined (type *mmapper has no field or method Lock) (typecheck)
        m.Lock()
          ^
../../../opt/go/1.20.1/src/syscall/syscall_unix.go:77:10: m.Unlock undefined (type *mmapper has no field or method Unlock) (typecheck)
        defer m.Unlock()

Version of golangci-lint

golangci-lint has version v1.51.2 built from (unknown, mod sum: "h1:yIcsT1X9ZYHdSpeWXRT1ORC/FPGSqDHbHsu9uk4FK7M=") on (unknown)

Configuration file

No config is used

Go environment

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/ubuntu/.cache/go-build"
GOENV="/home/ubuntu/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/ubuntu/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/ubuntu/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/opt/go/1.20.1"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/go/1.20.1/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.20.1"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"

Verbose output of running

INFO [config_reader] Config search paths: [./ /home/ubuntu/go_test /home/ubuntu /home /]
INFO [lintersdb] Active 7 linters: [errcheck gosimple govet ineffassign staticcheck typecheck unused]
INFO [loader] Go packages loading at mode 575 (deps|imports|name|types_sizes|compiled_files|exports_file|files) took 228.198453ms
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 331.031µs
INFO [linters_context/goanalysis] analyzers took 8.087655ms with top 10 stages: fact_deprecated: 1.057755ms, buildir: 848.488µs, inspect: 651.565µs, SA5012: 424.41µs, fact_purity: 414.288µs, ctrlflow: 357.827µs, nilness: 346.489µs, printf: 339.67µs, typedness: 326.735µs, SA1019: 125.786µs
INFO [runner/max_same_issues] 8/11 issues with text "String not declared by package unsafe" were hidden, use --max-same-issues
INFO [runner/max_same_issues] 4/7 issues with text "StringData not declared by package unsafe" were hidden, use --max-same-issues
INFO [runner] Issues before processing: 2411, after processing: 16
INFO [runner] Processors filtering stat (out/in): path_shortener: 16/16, filename_unadjuster: 2411/2411, path_prettifier: 2411/2411, identifier_marker: 2411/2411, nolint: 2411/2411, source_code: 16/16, exclude: 2411/2411, exclude-rules: 2411/2411, uniq_by_line: 28/2411, diff: 28/28, sort_results: 16/16, path_prefixer: 16/16, skip_dirs: 2411/2411, autogenerated_exclude: 2411/2411, max_same_issues: 16/28, max_from_linter: 16/16, severity-rules: 16/16, cgo: 2411/2411, skip_files: 2411/2411, max_per_file_from_linter: 28/28
INFO [runner] processing took 144.764592ms with stages: nolint: 46.638884ms, identifier_marker: 42.717909ms, exclude-rules: 42.481036ms, cgo: 4.867762ms, path_prettifier: 3.982078ms, skip_dirs: 1.763918ms, filename_unadjuster: 990.348µs, source_code: 532.595µs, autogenerated_exclude: 472.838µs, uniq_by_line: 218.598µs, max_same_issues: 81.359µs, path_shortener: 6.296µs, max_per_file_from_linter: 4.606µs, max_from_linter: 3.718µs, skip_files: 758ns, diff: 497ns, exclude: 474ns, sort_results: 427ns, severity-rules: 337ns, path_prefixer: 154ns
INFO [runner] linters took 895.755039ms with stages: goanalysis_metalinter: 750.550032ms
../../../opt/go/1.20.1/src/runtime/debuglog.go:296:20: StringData not declared by package unsafe (typecheck)
        strData := unsafe.StringData(x)
                          ^
../../../opt/go/1.20.1/src/runtime/heapdump.go:159:37: StringData not declared by package unsafe (typecheck)
        dumpmemrange(unsafe.Pointer(unsafe.StringData(s)), uintptr(len(s)))
                                           ^
../../../opt/go/1.20.1/src/runtime/heapdump.go:202:32: StringData not declared by package unsafe (typecheck)
                dwrite(unsafe.Pointer(unsafe.StringData(pkgpath)), uintptr(len(pkgpath)))
                                             ^
../../../opt/go/1.20.1/src/runtime/proc.go:658:16: String not declared by package unsafe (typecheck)
                        s := unsafe.String(p, findnull(p))
                                    ^
../../../opt/go/1.20.1/src/runtime/string.go:105:17: String not declared by package unsafe (typecheck)
                return unsafe.String((*byte)(p), 1)
                              ^
../../../opt/go/1.20.1/src/runtime/string.go:115:16: String not declared by package unsafe (typecheck)
        return unsafe.String((*byte)(p), n)
                      ^
../../../opt/go/1.20.1/src/internal/fmtsort/sort.go:182:1: missing return (typecheck)
}
^
../../../opt/go/1.20.1/src/io/pipe.go:22:4: a.Lock undefined (type *onceError has no field or method Lock) (typecheck)
        a.Lock()
          ^
../../../opt/go/1.20.1/src/io/pipe.go:23:10: a.Unlock undefined (type *onceError has no field or method Unlock) (typecheck)
        defer a.Unlock()
                ^
../../../opt/go/1.20.1/src/io/pipe.go:30:4: a.Lock undefined (type *onceError has no field or method Lock) (typecheck)
        a.Lock()
          ^
../../../opt/go/1.20.1/src/io/pipe.go:31:10: a.Unlock undefined (type *onceError has no field or method Unlock) (typecheck)
        defer a.Unlock()
                ^
../../../opt/go/1.20.1/src/os/file_unix.go:416:15: invalid operation: cannot compare d.info != nil (operator != not defined on untyped nil) (typecheck)
        if d.info != nil {
                     ^
../../../opt/go/1.20.1/src/syscall/syscall_unix.go:63:4: m.Lock undefined (type *mmapper has no field or method Lock) (typecheck)
        m.Lock()
          ^
../../../opt/go/1.20.1/src/syscall/syscall_unix.go:64:10: m.Unlock undefined (type *mmapper has no field or method Unlock) (typecheck)
        defer m.Unlock()
                ^
../../../opt/go/1.20.1/src/syscall/syscall_unix.go:76:4: m.Lock undefined (type *mmapper has no field or method Lock) (typecheck)
        m.Lock()
          ^
../../../opt/go/1.20.1/src/syscall/syscall_unix.go:77:10: m.Unlock undefined (type *mmapper has no field or method Unlock) (typecheck)
        defer m.Unlock()
                ^
INFO File cache stats: 8 entries of total size 266.1KiB
INFO Memory: 13 samples, avg is 91.9MB, max is 142.3MB
INFO Execution took 1.144593778s

Code example or link to a public repository

package main

import "fmt"

func main() {
        fmt.Println("Hello")
}
@PanKaker PanKaker added the bug Something isn't working label Mar 3, 2023
@boring-cyborg
Copy link

boring-cyborg bot commented Mar 3, 2023

Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors.

@PanKaker
Copy link
Author

PanKaker commented Mar 3, 2023

I've tried to use binary 1.51.1 version and this issues didn't appear.
Looks like it's something connected with 1.51.2 version

@PanKaker
Copy link
Author

PanKaker commented Mar 3, 2023

Small update:
Looks like this version was installed by Visual Studio code.

When I used binary (1.51.2) from the release page, I didn't face this issues

@PanKaker
Copy link
Author

PanKaker commented Mar 3, 2023

I'm closing the issue

@PanKaker PanKaker closed this as completed Mar 3, 2023
@eliasp
Copy link

eliasp commented Mar 3, 2023

Seeing the same issue here, where golangci-lint's typecheck linter fails, as it analyzes imported code - here: net/http:
Using version 1.51.2.

../../../../../nix/store/r53hy5fziwxx65487jdv8nci8xajqyds-go-1.20.1/share/go/src/runtime/debuglog.go:296:20: StringData not declared by package unsafe (typecheck)
        strData := unsafe.StringData(x)
                          ^
../../../../../nix/store/r53hy5fziwxx65487jdv8nci8xajqyds-go-1.20.1/share/go/src/runtime/heapdump.go:159:37: StringData not declared by package unsafe (typecheck)
        dumpmemrange(unsafe.Pointer(unsafe.StringData(s)), uintptr(len(s)))
                                           ^
../../../../../nix/store/r53hy5fziwxx65487jdv8nci8xajqyds-go-1.20.1/share/go/src/runtime/heapdump.go:202:32: StringData not declared by package unsafe (typecheck)
                dwrite(unsafe.Pointer(unsafe.StringData(pkgpath)), uintptr(len(pkgpath)))
                                             ^
../../../../../nix/store/r53hy5fziwxx65487jdv8nci8xajqyds-go-1.20.1/share/go/src/runtime/proc.go:658:16: String not declared by package unsafe (typecheck)
                        s := unsafe.String(p, findnull(p))
                                    ^
../../../../../nix/store/r53hy5fziwxx65487jdv8nci8xajqyds-go-1.20.1/share/go/src/runtime/string.go:105:17: String not declared by package unsafe (typecheck)
                return unsafe.String((*byte)(p), 1)
                              ^
../../../../../nix/store/r53hy5fziwxx65487jdv8nci8xajqyds-go-1.20.1/share/go/src/runtime/string.go:115:16: String not declared by package unsafe (typecheck)
        return unsafe.String((*byte)(p), n)
[...]

@PanKaker
Copy link
Author

PanKaker commented Mar 3, 2023

@eliasp Did you try to install the latest version from the release page?

I think my problem was with VS Code:
I changed the linter in VS Code settings, and it downloaded a strange version.

I've tried to download binary from the release page and these issues disappeared.

@PanKaker PanKaker reopened this Mar 3, 2023
@eliasp
Copy link

eliasp commented Mar 3, 2023

That's weird - it works with the one from the release page.
The version I used before is the one included in nixpkgs - it seems there were changes in golangci-lint which have this effect on binaries built by 3rd parties.

I'll investigate further and try to get to the root of this.

@ldez ldez added question Further information is requested and removed bug Something isn't working labels Mar 3, 2023
@ldez
Copy link
Member

ldez commented Mar 3, 2023

Hello, it's not a problem with golangci-lint.

typecheck is not a real linter it's just a way to parse/display "compilation" and linters errors (linter reports are not errors).

@ldez ldez closed this as completed Mar 3, 2023
@natefinch
Copy link
Contributor

typecheck is not a real linter it's just a way to parse/display "compilation" and linters errors (linter reports are not errors).

I've seen you post this on other issues as well, but it's not a helpful response. I'm facing this error in my CI right now. It may not be a linter message, but it's definitely being emitted from golangci-lint.

My guess is that this is a problem of golangci-lint being built with a different (probably lower) version of Go than what is used to build the code it's linting.

@natefinch
Copy link
Contributor

Yeah, can confirm, I updated golangci-lint to be built with go1.20 (previously 1.18), and the repo I was linting was built with go1.20, and that fixed the problem.

@bombsimon
Copy link
Member

I've seen you post this on other issues as well, but it's not a helpful response.

I added a suggested list to #3460 for things to try when troubleshooting find the root cause. Just to be clear did you just update the version of golangci-lint or are you building your binary yourself and rebuilt it with go1.20 now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants