Esempio n. 1
0
func (pkg *Package) check(fs *token.FileSet, astFiles []*ast.File) error {
	pkg.types = make(map[ast.Expr]types.Type)
	pkg.values = make(map[ast.Expr]exact.Value)
	exprFn := func(x ast.Expr, typ types.Type, val exact.Value) {
		pkg.types[x] = typ
		if val != nil {
			pkg.values[x] = val
		}
	}
	// By providing the Context with our own error function, it will continue
	// past the first error. There is no need for that function to do anything.
	context := types.Context{
		Expr:  exprFn,
		Error: func(error) {},
	}
	_, err := context.Check(pkg.path, fs, astFiles...)
	return err
}
Esempio n. 2
0
func processPackage(path string, fset *token.FileSet, files []*ast.File) {
	type bailout struct{}
	ctxt := types.Context{
		Error: func(err error) {
			if !*allErrors && errorCount >= 10 {
				panic(bailout{})
			}
			report(err)
		},
	}

	defer func() {
		switch err := recover().(type) {
		case nil, bailout:
		default:
			panic(err)
		}
	}()

	ctxt.Check(path, fset, files...)
}