Standard library / go/types
go/types.Error
Represents a type-checking diagnostic with file set, position, message and soft-error flag. Expected stdout: 'true true\n'.
Formal Syntax & Structure
go syntaxgo
type Error struct { Fset *token.FileSet Pos token.Pos Msg string Soft bool
}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 main() { f := token.NewFileSet() a, e := parser.ParseFile(f, "p.go", "package p; var X int = \"bad\"", 0) check(e) _, e = (&types.Config{}).Check("p", f, []*ast.File{a}, nil) v := e.(types.Error) fmt.Println(v.Pos.IsValid(), v.Msg != "")}