Standard library / go/types
go/types.NewTypeName()
Creates a type-name object; passing nil allows a subsequently constructed defined type to associate itself with the object. Expected stdout: 'Count true\n'.
Formal Syntax & Structure
go syntaxgo
func NewTypeName(pos token.Pos, pkg *Package, name string, typ Type) *TypeNameParameters & Attributes
| Name | Type | Description |
|---|---|---|
| pos | token.Pos | Source position in the associated file set. |
| pkg | *Package | Package containing the symbol; nil for package-independent objects. |
| name | string | Name of the symbol or package. |
| typ | Type | Type associated with the object or value. |
Return Value
*TypeName
Creates a type-name object; passing nil allows a subsequently constructed defined type to associate itself with the object.
Working Example
Example Snippetgo
package main
import ( "fmt" "go/types")
func main() { o := types.NewTypeName(0, nil, "Count", nil); fmt.Println(o.Name(), o.Type() == nil) }