Skip to content

fix: memory leaks when using go1.(N) with golangci-lint built with go1.(N-1) #5695

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

Merged
merged 1 commit into from
Apr 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/goanalysis/pkgerrors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type IllTypedError struct {
}

func (e *IllTypedError) Error() string {
return fmt.Sprintf("errors in package: %v", e.Pkg.Errors)
return fmt.Sprintf("IllTypedError: errors in package: %v", e.Pkg.Errors)
}

func BuildIssuesFromIllTypedError(errs []error, lintCtx *linter.Context) ([]result.Issue, error) {
Expand Down
11 changes: 11 additions & 0 deletions pkg/goanalysis/runner_loadingpackage.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import (

const unsafePkgName = "unsafe"

// https://github.com/golang/go/blob/go1.23.8/src/internal/types/errors/codes.go#L1484
const tooNew = 151

type loadingPackage struct {
pkg *packages.Package
imports map[string]*loadingPackage
Expand Down Expand Up @@ -436,6 +439,14 @@ func (lp *loadingPackage) convertError(err error) []packages.Error {

case types.Error:
// from type checker

// https://github.com/golang/go/blob/go1.23.8/src/go/types/api.go#L52-L57
if int(reflect.ValueOf(err).FieldByName("go116code").Int()) == tooNew {
// https://github.com/golang/go/blob/go1.23.8/src/go/types/check.go#L380
// https://github.com/golang/go/blob/go1.23.8/src/go/types/check.go#L349
panic(err.Msg)
}

errs = append(errs, packages.Error{
Pos: err.Fset.Position(err.Pos).String(),
Msg: err.Msg,
Expand Down
Loading