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" #8042

Closed
dvyukov opened this issue May 20, 2014 · 18 comments
Closed

cmd/compile: spurious "goto label jumps over declaration" #8042

dvyukov opened this issue May 20, 2014 · 18 comments
Milestone

Comments

@dvyukov
Copy link
Member

dvyukov commented May 20, 2014

go version devel +4a839bf01b58 Tue May 20 15:52:08 2014 +1000 + linux/amd64

The program is:
package main
func main() {
    goto label
    type X int
    label:
}

$ go build goto.go
goto.go:3: goto label jumps over declaration of X at goto.go:4

The spec only requires new variables to not come into scope:
"Executing the "goto" statement must not cause any variables to come into
scope that were not already in scope at the point of the goto".
@dvyukov
Copy link
Member Author

dvyukov commented May 20, 2014

Comment 1:

Labels changed: added repo-main.

@rsc
Copy link
Contributor

rsc commented May 20, 2014

Comment 2:

Labels changed: added release-go1.4.

Status changed to Accepted.

@rsc
Copy link
Contributor

rsc commented Sep 15, 2014

Comment 3:

Labels changed: added release-go1.5, removed release-go1.4.

@bradfitz bradfitz modified the milestone: Go1.5 Dec 16, 2014
@rsc rsc removed accepted labels Apr 14, 2015
@DanielMorsing
Copy link
Contributor

@gopherbot
Copy link

CL https://golang.org/cl/9442 mentions this issue.

@bradfitz
Copy link
Contributor

I reverted the fix, since it broke all the builds.

@rsc rsc changed the title cmd/gc: spurious "goto label jumps over declaration" cmd/compile: spurious "goto label jumps over declaration" Jun 8, 2015
@rsc
Copy link
Contributor

rsc commented Jun 29, 2015

Too late for Go 1.5.

@ghost
Copy link

ghost commented Feb 22, 2017

At the risk of sounding like a fool: suppose that the next line in main in dvyukov's example is

var v X = 0

What then? I think this is a problem with the spec, and not the toolchain.

@griesemer
Copy link
Contributor

@IronGopher If the declaration were about a variable X rather than a type, then it would be a correct error. The issue is that it's only an error if variables are coming into scope, not types or constants. The spec is clear. This is a compiler bug.

@griesemer griesemer self-assigned this Apr 18, 2017
@djadala
Copy link
Contributor

djadala commented Oct 2, 2017

CC @griesemer @dvyukov
If i modify original program as:

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

output is still:

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

go version
go version go1.9 linux/amd64

Should new bug be opened ?

@dvyukov
Copy link
Member Author

dvyukov commented Oct 2, 2017

@djadala

Should new bug be opened ?

yes

@djadala
Copy link
Contributor

djadala commented Oct 2, 2017

s/ type X int/ X := 0/

@odeke-em
Copy link
Member

odeke-em commented Oct 2, 2017

Never mind my last comment, your bug still stands even on the latest code @djadala :)

@djadala
Copy link
Contributor

djadala commented Oct 2, 2017

ok, new issue is #22101

@odeke-em
Copy link
Member

odeke-em commented Oct 2, 2017

Okay hold up though, your program isn't correct and you have made a new variable declaration with

goto L
X := 0

A goto shouldn't allow a variable that wasn't already in scope to come into scope. I don't see the bug here.

@odeke-em
Copy link
Member

odeke-em commented Oct 2, 2017

@djadala I've commented on the other issue that this isn't a bug, and coincidentally the spec provides a similar example to what you posted
https://golang.org/ref/spec#GotoStmt

Initially I had copied and pasted the original code without checking it, but on a closer look I deduced that this isn't a bug.

@djadala
Copy link
Contributor

djadala commented Oct 2, 2017

Sorry for noise,
i thought if variable is not used after label, this must compile, but i'm wrong.

@odeke-em
Copy link
Member

odeke-em commented Oct 2, 2017

Not a problem at all @djadala, thank you for checking up on the bug.

@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.
Projects
None yet
Development

No branches or pull requests

9 participants