Standard library / go/types

go/types.NewParam()

Creates a variable representing a function parameter. Expected stdout: 'x int\n'.

Formal Syntax & Structure

go syntaxgo
func NewParam(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 representing a function parameter.

Working Example

Example Snippetgo
package main
import (  "fmt"  "go/types")
func main() { p := types.NewParam(0, nil, "x", types.Typ[types.Int]); fmt.Println(p.Name(), p.Type()) }
Go Reference