@@ -196,20 +196,24 @@ func discoverGoRoot() (string, error) {
196196func 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}
0 commit comments