Skip to content

go/types: Unclear what typ param in NewTypeName is #22516

@willfaught

Description

@willfaught

https://golang.org/pkg/go/types/#NewTypeName:

func NewTypeName(pos token.Pos, pkg *Package, name string, typ Type) *TypeName

Is it the underlying type? If so, that's confusing, because the underlying type param for NewNamed is named "underlying" and this one is not.

https://golang.org/pkg/go/types/#NewNamed:

func NewNamed(obj *TypeName, underlying Type, methods []*Func) *Named

To construct a new named type, it's confusing why you have to supply a types.Type twice, especially if the typ param of NewTypeName isn't the underlying type:

// Make a new type with name Mytypename and underlying type string for package with path mypkgpath and name mypkgname:

var myPkg = types.NewPackage("mypkgpath", "mypkgname")
var myTypeName = types.NewTypeName(token.NoPos, myPkg, "Mytypename", ??????????)
var myType = types.NewNamed(myTypeName, types.Typ[types.String], nil)

What should the argument be for the typ param of the NewTypeName call above (where ?????????? is)? Why does TypeName need it?

Does this issue reproduce with the latest release (go1.9.2)?

Yes

System details

go version go1.9.1 darwin/amd64
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/willfaught/Developer/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.9.1/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.9.1/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/_1/ggvd2t1x7hz_185crsb36zlr0000gp/T/go-build024849979=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOROOT/bin/go version: go version go1.9.1 darwin/amd64
GOROOT/bin/go tool compile -V: compile version go1.9.1
uname -v: Darwin Kernel Version 17.0.0: Thu Aug 24 21:48:19 PDT 2017; root:xnu-4570.1.46~2/RELEASE_X86_64
ProductName:	Mac OS X
ProductVersion:	10.13
BuildVersion:	17A365
lldb --version: lldb-900.0.50.1
  Swift-4.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions