Standard library / go/types
go/types.Checker
Maintains the state of a package type-checking operation. Create it with NewChecker. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
type Checker struct { *Info
}Working Example
Example Snippetgo
package main
import ( "fmt" "go/ast" "go/parser" "go/token" "go/types")
func check(e error) { if e != nil { panic(e) }}func checker() (*types.Checker, *ast.File) { f := token.NewFileSet() a, e := parser.ParseFile(f, "p.go", "package p; var X = 42", 0) check(e) c := types.NewChecker(&types.Config{}, f, types.NewPackage("p", "p"), &types.Info{Defs: map[*ast.Ident]types.Object{}, Types: map[ast.Expr]types.TypeAndValue{}}) return c, a}
func main() { c, f := checker(); check(c.Files([]*ast.File{f})); fmt.Println(c.Info != nil) }