Skip to content

reflect: fmt did not invoke Kind.String method on MacOS #20438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
xgz123 opened this issue May 20, 2017 · 2 comments
Closed

reflect: fmt did not invoke Kind.String method on MacOS #20438

xgz123 opened this issue May 20, 2017 · 2 comments

Comments

@xgz123
Copy link

xgz123 commented May 20, 2017

What version of Go are you using (go version)?

go version go1.8.1 darwin/amd64

What operating system and processor architecture are you using (go env)?

macOS Sierra

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="***/go"
GORACE=""
GOROOT="***/go"
GOTOOLDIR="***/go/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/bl/s4qsyy7s6cx4wj6tnhw2mb6w0000gn/T/go-build081416673=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

What did you do?

package main

import (
	"fmt"
	"reflect"
)

type X int

func main() {
	var a X = 100
	t := reflect.TypeOf(a)
	fmt.Println(t.Name(), t.Kind())
}

What did you expect to see?

play.golang.org has the right output:X int

What did you see instead?

my result: X 2

@xgz123 xgz123 changed the title reflect returned wrong kind reflect returned wrong kind on macOS May 20, 2017
@ianlancetaylor ianlancetaylor changed the title reflect returned wrong kind on macOS reflect: fmt did not invoke Kind.String method on MacOS May 20, 2017
@ianlancetaylor
Copy link
Member

The problem is not that reflect.Kind returned the wrong value. The problem is that fmt.Println did not invoke the String method of reflect.Kind. The value of Int is in fact 2.

Are you sure that you ran the exact program you show on MacOS? For example, you did not change fmt.Println to simply println?

@xgz123
Copy link
Author

xgz123 commented May 21, 2017

@ianlancetaylor ...You are 100% right!

@xgz123 xgz123 closed this as completed May 21, 2017
@golang golang locked and limited conversation to collaborators May 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants