Standard library / go/types

go/types.WriteExpr()

Writes the diagnostic expression representation to a bytes.Buffer. Expected stdout: 'x + 1\n'.

Formal Syntax & Structure

go syntaxgo
func WriteExpr(buf *bytes.Buffer, x ast.Expr)

Parameters & Attributes

NameTypeDescription
buf*bytes.BufferInput to the operation as described above.
xast.ExprFirst type or expression to inspect.

Working Example

Example Snippetgo
package main
import (  "bytes"  "fmt"  "go/parser"  "go/types")
func check(e error) {  if e != nil {    panic(e)  }}
func main() {  e, err := parser.ParseExpr("x+1")  check(err)  var b bytes.Buffer  types.WriteExpr(&b, e)  fmt.Println(b.String())}
Go Reference