Standard library / go/types

go/types.Named.SetUnderlying()

Sets a defined type’s underlying type. Use only while constructing a type, before sharing it. Expected stdout: 'int\n'.

Formal Syntax & Structure

go syntaxgo
func (t *Named) SetUnderlying(underlying Type)

Parameters & Attributes

NameTypeDescription
underlyingTypeUnderlying type of the defined type.

Working Example

Example Snippetgo
package main
import (  "fmt"  "go/types")
func main() {  v := types.NewNamed(types.NewTypeName(0, nil, "N", nil), nil, nil)  v.SetUnderlying(types.Typ[types.Int])  fmt.Println(v.Underlying())}
Go Reference