You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For example, "golang.org/x/net/context".Context now aliases "context".Context. I expected the Lookup call for the "go/types".Scope for the "go/types".Package for "context" to give me the "go/types".Type for the "golang.org/x/net/context".Context declaration, but it gave me the one for the "context".Context declaration, so the result of "go/types".Named.Obj().IsAlias() for that type is false when I expected true. Is there another way you're supposed to look up the type of a package's alias declaration by name, such that IsAlias returns true? If not, is there a workaround?
Note that it gets an error in the playground because golang.org/x/net/context isn't installed. You'll have to run it on your own machine for it to work.
What did you expect to see?
golang.org/x/net/context.Context is alias: actual true, expected true
What did you see instead?
golang.org/x/net/context.Context is alias: actual false, expected true
System details
go version go1.9.2 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.2/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.9.2/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-build802077183=/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.2 darwin/amd64
GOROOT/bin/go tool compile -V: compile version go1.9.2
uname -v: Darwin Kernel Version 17.2.0: Fri Sep 29 18:27:05 PDT 2017; root:xnu-4570.20.62~3/RELEASE_X86_64
ProductName: Mac OS X
ProductVersion: 10.13.1
BuildVersion: 17B1003
lldb --version: lldb-900.0.57
Swift-4.0
The text was updated successfully, but these errors were encountered:
This is working as expected and you have a bug in your code: You are calling the IsAlias() method on the original type name rather than the aliased type name. Keep in mind that a Type is never an alias, it's a TypeName that may be an alias (names can be aliases, types are never aliases).
Or in other words, the Type of a TypeName object is always the actual (non-alias) type, no matter if the TypeName is an alias or not. In your code
you are getting the Type of the Context object, which is the original (std lib) named Context Type. Then you look up it's TypeName Object, which is (std lib) context.Context, and of course that's not an alias.
On the other hand, if you check if the looked up Context object is an an alias, you will get the expected result:
For example, "golang.org/x/net/context".Context now aliases "context".Context. I expected the Lookup call for the "go/types".Scope for the "go/types".Package for "context" to give me the "go/types".Type for the "golang.org/x/net/context".Context declaration, but it gave me the one for the "context".Context declaration, so the result of "go/types".Named.Obj().IsAlias() for that type is false when I expected true. Is there another way you're supposed to look up the type of a package's alias declaration by name, such that IsAlias returns true? If not, is there a workaround?
What did you do?
https://play.golang.org/p/oIWD5Ok2Xl
Note that it gets an error in the playground because golang.org/x/net/context isn't installed. You'll have to run it on your own machine for it to work.
What did you expect to see?
What did you see instead?
System details
The text was updated successfully, but these errors were encountered: