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

cmd/compile: spurious "goto label jumps over declaration" - 2 #22101

Closed
djadala opened this issue Oct 2, 2017 · 2 comments

Comments

Projects
None yet
3 participants
@djadala
Copy link
Contributor

commented Oct 2, 2017

Please answer these questions before submitting your issue. Thanks!

related to #8042 , this program does not compile:

package main
func main() {
    goto label
    X := 0
    label:
}

What did you do?

try to compile above

What did you expect to see?

to compile OK

What did you see instead?

error:

go build t.go
# command-line-arguments
./t.go:3:10: goto label jumps over declaration of X at ./t.go:4:7

System details

go version go1.9 linux/amd64
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/jambo/golang:/home/jambo/github:/home/jambo/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="/usr/bin/gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build694150748=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
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 linux/amd64
GOROOT/bin/go tool compile -V: compile version go1.9
uname -sr: Linux 4.9.0-0.bpo.3-amd64
LSB Version:	core-2.0-amd64:core-2.0-noarch:core-3.0-amd64:core-3.0-noarch:core-3.1-amd64:core-3.1-noarch:core-3.2-amd64:core-3.2-noarch:core-4.0-amd64:core-4.0-noarch:core-4.1-amd64:core-4.1-noarch:security-4.0-amd64:security-4.0-noarch:security-4.1-amd64:security-4.1-noarch
Distributor ID:	Debian
Description:	Debian GNU/Linux 8.9 (jessie)
Release:	8.9
Codename:	jessie
/lib/x86_64-linux-gnu/libc.so.6: GNU C Library (Debian GLIBC 2.19-18+deb8u10) stable release version 2.19, by Roland McGrath et al.
gdb --version: GNU gdb (Debian 7.7.1+dfsg-5) 7.7.1
@odeke-em

This comment has been minimized.

Copy link
Member

commented Oct 2, 2017

This isn't a bug, unless am mistaken but the deal is that jumping to a label shouldn't cause new variables to come into scope if it wasn't already in scope i.e

goto L
X := 0
L:

introduces a new variable X to go into scope. The original bug declared a type not a variable

X := 0
goto L
L:

and

goto L
L:
  X := 0

are correct but not the code reported.

For extra reference, we can take a look at the spec as well https://golang.org/ref/spec#GotoStmt with the same example coincidentally quoted there.

@griesemer @mdempsky please feel to reopen if am wrong.

@odeke-em odeke-em closed this Oct 2, 2017

@djadala

This comment has been minimized.

Copy link
Contributor Author

commented Oct 2, 2017

Ok, you are right, i thought if variable is not used after label, this must compile, but I'm wrong.
Can be modified to:

func main() {
	goto label
	{
		X := 0
		_ = X
	}
label:
}

@golang golang locked and limited conversation to collaborators Oct 2, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.