Skip to content

Commit 199d460

Browse files
author
golangci
authored
Merge pull request #43 from golangci/support/fix-panic-in-fast-mode
#40: fix panic in fast mode
2 parents 0eb6aa7 + 5646c61 commit 199d460

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

Makefile

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
test:
22
go install ./cmd/...
3-
golangci-lint run
3+
golangci-lint run -v
4+
golangci-lint run --fast --no-config -v
5+
golangci-lint run --fast --no-config -v
6+
golangci-lint run --no-config -v
7+
golangci-lint run --fast --no-config -v ./pkg/testdata/with_issues/typecheck.go
48
go test -v -race ./...

pkg/commands/run.go

+18-12
Original file line numberDiff line numberDiff line change
@@ -196,20 +196,24 @@ func discoverGoRoot() (string, error) {
196196
func separateNotCompilingPackages(lintCtx *golinters.Context) {
197197
prog := lintCtx.Program
198198

199-
compilingCreated := make([]*loader.PackageInfo, 0, len(prog.Created))
200-
for _, info := range prog.Created {
201-
if len(info.Errors) != 0 {
202-
lintCtx.NotCompilingPackages = append(lintCtx.NotCompilingPackages, info)
203-
} else {
204-
compilingCreated = append(compilingCreated, info)
199+
if prog.Created != nil {
200+
compilingCreated := make([]*loader.PackageInfo, 0, len(prog.Created))
201+
for _, info := range prog.Created {
202+
if len(info.Errors) != 0 {
203+
lintCtx.NotCompilingPackages = append(lintCtx.NotCompilingPackages, info)
204+
} else {
205+
compilingCreated = append(compilingCreated, info)
206+
}
205207
}
208+
prog.Created = compilingCreated
206209
}
207-
prog.Created = compilingCreated
208210

209-
for k, info := range prog.Imported {
210-
if len(info.Errors) != 0 {
211-
lintCtx.NotCompilingPackages = append(lintCtx.NotCompilingPackages, info)
212-
delete(prog.Imported, k)
211+
if prog.Imported != nil {
212+
for k, info := range prog.Imported {
213+
if len(info.Errors) != 0 {
214+
lintCtx.NotCompilingPackages = append(lintCtx.NotCompilingPackages, info)
215+
delete(prog.Imported, k)
216+
}
213217
}
214218
}
215219
}
@@ -261,7 +265,9 @@ func buildLintCtx(ctx context.Context, linters []pkg.Linter, cfg *config.Config)
261265
ASTCache: astCache,
262266
}
263267

264-
separateNotCompilingPackages(ret)
268+
if prog != nil {
269+
separateNotCompilingPackages(ret)
270+
}
265271

266272
return ret, nil
267273
}

pkg/golinters/typecheck.go

+4
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ func (lint TypeCheck) parseError(err error) *result.Issue {
6262
}
6363

6464
func (lint TypeCheck) Run(ctx context.Context, lintCtx *Context) ([]result.Issue, error) {
65+
if lintCtx.NotCompilingPackages == nil {
66+
return nil, nil
67+
}
68+
6569
var res []result.Issue
6670
for _, pkg := range lintCtx.NotCompilingPackages {
6771
for _, err := range pkg.Errors {

0 commit comments

Comments
 (0)