Skip to content
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

fix issue [#59] #70

Merged
merged 1 commit into from
Sep 21, 2018
Merged
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
18 changes: 17 additions & 1 deletion lint/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ func (p *Package) TypeCheck() error {
anyFile = f
astFiles = append(astFiles, f.AST)
}
typesPkg, err := config.Check(anyFile.AST.Name.Name, p.fset, astFiles, info)

typesPkg, err := check(config, anyFile.AST.Name.Name, p.fset, astFiles, info)

// Remember the typechecking info, even if config.Check failed,
// since we will get partial information.
p.TypesPkg = typesPkg
Expand All @@ -86,6 +88,20 @@ func (p *Package) TypeCheck() error {
return err
}

// check function encapsulates the call to go/types.Config.Check method and
// recovers if the called method panics (see issue #59)
func check(config *types.Config, n string, fset *token.FileSet, astFiles []*ast.File, info *types.Info) (p *types.Package, err error) {
defer func() {
if r := recover(); r != nil {
err, _ = r.(error)
p = nil
return
}
}()

return config.Check(n, fset, astFiles, info)
}

// TypeOf returns the type of an expression.
func (p *Package) TypeOf(expr ast.Expr) types.Type {
if p.TypesInfo == nil {
Expand Down