Skip to content
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

Switch bug #32647

Closed
luthfikw opened this issue Jun 17, 2019 · 1 comment
Closed

Switch bug #32647

luthfikw opened this issue Jun 17, 2019 · 1 comment

Comments

@luthfikw
Copy link

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

$ go version
go version go1.12.3 darwin/amd64

Does this issue reproduce with the latest release?

In reflect.Kind case switch not working properly
i write example code switch statement code
there program exited without print something

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

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/gearintellix/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/gearintellix/Sites/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.12.3/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.12.3/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/fw/zkl81fnd2d966l2_jvddn0gw0000gn/T/go-build252307363=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you expect to see?

that must be

OK 50

What did you see instead?

nothing

@ALTree
Copy link
Member

ALTree commented Jun 17, 2019

In Go, the switch statement doesn't have automatic fallthrough like in C. See: https://tour.golang.org/flowcontrol/9

In your example, v is an Int but your Int case in the switch is empty, so nothing is printed. Do this:

switch val.Kind() {
	case reflect.Int:
		fmt.Println("OK", v)

and you'll see "OK" printed.

Closing here, since this is not Go bug.

@ALTree ALTree closed this as completed Jun 17, 2019
@golang golang locked and limited conversation to collaborators Jun 16, 2020
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