Standard library / go/types

go/types.TypeAndValue

Describes the type and optional exact constant value of an expression; predicates classify its operand mode. Expected stdout: 'untyped int 5\n'.

Formal Syntax & Structure

go syntaxgo
type TypeAndValue struct {  Type  Type  Value constant.Value}

Working Example

Example Snippetgo
package main
import (  "fmt"  "go/token"  "go/types")
func check(e error) {  if e != nil {    panic(e)  }}
func main() {  tv, e := types.Eval(token.NewFileSet(), nil, 0, "2+3")  check(e)  fmt.Println(tv.Type, tv.Value.ExactString())}
Go Reference