Standard library / go/types

go/types.NewVar()

Creates a variable object, not runtime storage. Expected stdout: 'count int false\n'.

Formal Syntax & Structure

go syntaxgo
func NewVar(pos token.Pos, pkg *Package, name string, typ Type) *Var

Parameters & Attributes

NameTypeDescription
postoken.PosSource position in the associated file set.
pkg*PackagePackage containing the symbol; nil for package-independent objects.
namestringName of the symbol or package.
typTypeType associated with the object or value.

Return Value

*Var

Creates a variable object, not runtime storage.

Working Example

Example Snippetgo
package main
import (  "fmt"  "go/types")
func main() {  v := types.NewVar(0, nil, "count", types.Typ[types.Int])  fmt.Println(v.Name(), v.Type(), v.IsField())}
Go Reference