Skip to content

Commit 65b3c07

Browse files
authored
fix: memory leaks when using go1.(N) with golangci-lint built with with go1.(N-1) (#5695)
1 parent 7eac7fa commit 65b3c07

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

pkg/goanalysis/pkgerrors/errors.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type IllTypedError struct {
1515
}
1616

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

2121
func BuildIssuesFromIllTypedError(errs []error, lintCtx *linter.Context) ([]result.Issue, error) {

pkg/goanalysis/runner_loadingpackage.go

+11
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ import (
2424

2525
const unsafePkgName = "unsafe"
2626

27+
// https://github.com/golang/go/blob/go1.23.8/src/internal/types/errors/codes.go#L1484
28+
const tooNew = 151
29+
2730
type loadingPackage struct {
2831
pkg *packages.Package
2932
imports map[string]*loadingPackage
@@ -436,6 +439,14 @@ func (lp *loadingPackage) convertError(err error) []packages.Error {
436439

437440
case types.Error:
438441
// from type checker
442+
443+
// https://github.com/golang/go/blob/go1.23.8/src/go/types/api.go#L52-L57
444+
if int(reflect.ValueOf(err).FieldByName("go116code").Int()) == tooNew {
445+
// https://github.com/golang/go/blob/go1.23.8/src/go/types/check.go#L380
446+
// https://github.com/golang/go/blob/go1.23.8/src/go/types/check.go#L349
447+
panic(err.Msg)
448+
}
449+
439450
errs = append(errs, packages.Error{
440451
Pos: err.Fset.Position(err.Pos).String(),
441452
Msg: err.Msg,

0 commit comments

Comments
 (0)