mirror of
https://github.com/mgechev/revive.git
synced 2025-01-24 03:47:45 +02:00
parent
0c79a9c405
commit
bd4139713d
@ -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
|
||||
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user