diff --git a/x/typesutil/check.go b/x/typesutil/check.go index f91650562..dad82567d 100644 --- a/x/typesutil/check.go +++ b/x/typesutil/check.go @@ -111,6 +111,9 @@ func (p *Checker) Files(goFiles []*goast.File, gopFiles []*ast.File) (err error) gopfs := make(map[string]*ast.File) for _, goFile := range goFiles { f := fset.File(goFile.Pos()) + if f == nil { + continue + } file := f.Name() fname := filepath.Base(file) if strings.HasPrefix(fname, "gop_autogen") { @@ -121,6 +124,9 @@ func (p *Checker) Files(goFiles []*goast.File, gopFiles []*ast.File) (err error) } for _, gopFile := range gopFiles { f := fset.File(gopFile.Pos()) + if f == nil { + continue + } gopfs[f.Name()] = gopFile } if debugVerbose { diff --git a/x/typesutil/check_test.go b/x/typesutil/check_test.go index fbbbe0acb..703118c1f 100644 --- a/x/typesutil/check_test.go +++ b/x/typesutil/check_test.go @@ -185,3 +185,13 @@ var i int = "hello" t.Fatal("no error") } } + +func TestBadFile(t *testing.T) { + conf := &types.Config{} + opt := &typesutil.Config{} + opt.Fset = token.NewFileSet() + opt.Types = types.NewPackage("", "main") + checker := typesutil.NewChecker(conf, opt, nil, nil) + _ = checker.Files([]*goast.File{&goast.File{Name: goast.NewIdent("main")}}, + []*ast.File{&ast.File{Name: ast.NewIdent("main")}}) +}