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 over type/const declarations is erroneously rejected #19088

Closed
mdempsky opened this issue Feb 14, 2017 · 7 comments

Comments

Projects
None yet
5 participants
@mdempsky
Copy link
Member

commented Feb 14, 2017

The Go spec (section "Goto statements") says "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."

cmd/compile erroneously rejects this code:

package p

func f() {
	goto out
	type x int
out:
}

with

/tmp/goto.go:4: goto out jumps over declaration of x at /tmp/goto.go:5

@mdempsky mdempsky added this to the Go1.9 milestone Feb 14, 2017

@mdempsky mdempsky self-assigned this Feb 14, 2017

@mdempsky mdempsky changed the title cmd/compile: goto over type/const declarations is valid cmd/compile: goto over type/const declarations is erroneously rejected Feb 14, 2017

@mdempsky

This comment has been minimized.

Copy link
Member Author

commented Feb 14, 2017

Also, go/types accepts the test case.

@dr2chase

This comment has been minimized.

Copy link
Contributor

commented Feb 14, 2017

Can't we argue that there is a scope between "out:" and "}" ?

@mdempsky

This comment has been minimized.

Copy link
Member Author

commented Feb 14, 2017

@dr2chase Sorry, I'm not sure I understand your question.

The Go spec forbids gotos that jump over variable declarations such as:

  goto out
  var x int
out:

The issue is that cmd/compile (and gccgo) are also rejecting gotos that jump over type and constant declarations.

@dr2chase

This comment has been minimized.

Copy link
Contributor

commented Feb 15, 2017

Ah, oops, never mind.

@griesemer

This comment has been minimized.

Copy link
Contributor

commented Feb 15, 2017

Probably not urgent since we lived with this forever. Yet also safe to fix because it will be backward-compatible with existing code (it's lifting a restriction).

@ALTree

This comment has been minimized.

Copy link
Member

commented Feb 15, 2017

Exact dup of #13521 and #8042.

@mdempsky

This comment has been minimized.

Copy link
Member Author

commented Feb 15, 2017

@ALTree Good finds. Closing as duplicate of #8042.

@mdempsky mdempsky closed this Feb 15, 2017

@golang golang locked and limited conversation to collaborators Feb 15, 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.