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: "goto jumps over declaration" error is unclear for multiple jumped decls #27912

Closed
willfaught opened this issue Sep 27, 2018 · 6 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@willfaught
Copy link
Contributor

What did you do?

https://play.golang.org/p/anZpKB9l1ov

What did you expect to see?

prog.go:8:7: goto Default jumps over declaration of b1 at prog.go:9:5

(B1 is the first declaration (on line 9) following the goto.)

What did you see instead?

prog.go:8:7: goto Default jumps over declaration of b9 at prog.go:17:5

(B9 is the last declaration (on line 17) following the goto.)

It's confusing what this error means if you're not familiar with the goto variable scope rule, since there are lots of other variable decls in this example that are also skipped that are even closer to the goto statement.

System details

go version go1.11 darwin/amd64
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/will/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/will/Developer/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.11/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.11/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
GOROOT/bin/go version: go version go1.11 darwin/amd64
GOROOT/bin/go tool compile -V: compile version go1.11
uname -v: Darwin Kernel Version 17.7.0: Thu Jun 21 22:53:14 PDT 2018; root:xnu-4570.71.2~1/RELEASE_X86_64
ProductName:	Mac OS X
ProductVersion:	10.13.6
BuildVersion:	17G65
lldb --version: lldb-1000.11.37.1
  Swift-4.2
@willfaught willfaught changed the title "goto jumps over declaration" error is unclear "goto jumps over declaration" error is unclear for multiple jumped decls Sep 27, 2018
@cznic
Copy link
Contributor

cznic commented Sep 28, 2018

since there are lots of other variable decls in this example that are also skipped that are even closer to the goto statement.

That's a valid approach. OTOH, b9 is closest to the goto's target Default. That's also a perfectly valid approach.

@willfaught
Copy link
Contributor Author

The issue wasn't validity, since the error is technically correct; it's that it left me thinking "why is it okay for b1–b8 but not b9"? The go compiler only reports 8 or so of the topmost (in terms of file position) errors before quitting altogether, so the current approach here of reporting the bottommost error is confusing because it suggests that there were no previous errors.

@cznic
Copy link
Contributor

cznic commented Sep 28, 2018

It's not okay for b1-b8. It would be ok iff when b9 is removed and compiler would then accept the code.

I think the compiler "discovers' the error only after finally seeing the label and then it intentionally reports the last and thus nearest jumped-over declaration. Reporting all of the others is definitely possible, the question is if that adds any value for the user. I don't think so.

@katiehockman katiehockman changed the title "goto jumps over declaration" error is unclear for multiple jumped decls cmd/compile: "goto jumps over declaration" error is unclear for multiple jumped decls Sep 28, 2018
@katiehockman katiehockman added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 28, 2018
@katiehockman
Copy link
Contributor

/cc @randall77

@randall77
Copy link
Contributor

It would be fine by me to report b1 instead of b9. I think it is a small improvement to report earlier decls, for the reason @willfaught described.
What I don't want is this:

prog.go:8:7: goto Default jumps over declaration of b1 at prog.go:9:5
prog.go:8:7: goto Default jumps over declaration of b2 at prog.go:10:5
prog.go:8:7: goto Default jumps over declaration of b3 at prog.go:11:5
prog.go:8:7: goto Default jumps over declaration of b4 at prog.go:12:5
prog.go:8:7: goto Default jumps over declaration of b5 at prog.go:13:5
prog.go:8:7: goto Default jumps over declaration of b6 at prog.go:14:5
prog.go:8:7: goto Default jumps over declaration of b7 at prog.go:15:5
prog.go:8:7: goto Default jumps over declaration of b8 at prog.go:16:5
prog.go:8:7: goto Default jumps over declaration of b9 at prog.go:17:5

It's unnecessary stutter, each less useful for fixing the problem than the last.

It would also be ok to do something like this, if there's more than one decl being jumped over:

prog.go:8:7: goto Default jumps over declarations, one of which is b9 at prog.go:17:5

@randall77 randall77 added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Sep 28, 2018
@randall77 randall77 added this to the Unplanned milestone Sep 28, 2018
@willfaught
Copy link
Contributor Author

Closing due to no activity.

@willfaught willfaught closed this as not planned Won't fix, can't repro, duplicate, stale Nov 19, 2022
@golang golang locked and limited conversation to collaborators Nov 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants