Standard library / go/types
go/types.Error.Error()
Formats a type-checking diagnostic with its source location. Expected stdout: 'true true\n'.
Formal Syntax & Structure
go syntaxgo
func (err Error) Error() stringReturn Value
string
Formats a type-checking diagnostic with its source location.
Working Example
Example Snippetgo
package main
import ( "fmt" "go/ast" "go/parser" "go/token" "go/types" "strings")
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(strings.Contains(v.Error(), "p.go:"), strings.Contains(v.Error(), "cannot use"))}