Example #1
0
func (pkg *Package) check(fs *token.FileSet, astFiles []*ast.File) error {
	pkg.types = make(map[ast.Expr]Type)
	pkg.values = make(map[ast.Expr]interface{})
	exprFn := func(x ast.Expr, typ types.Type, val interface{}) {
		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(fs, astFiles)
	return err
}
Example #2
0
func processPackage(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(fset, files)
}