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: missing "out of bounds" error slicing [0]T #20749

Closed
josharian opened this issue Jun 22, 2017 · 5 comments
Closed

cmd/compile: missing "out of bounds" error slicing [0]T #20749

josharian opened this issue Jun 22, 2017 · 5 comments
Milestone

Comments

@josharian
Copy link
Contributor

package p

func f() {
	var b [0]struct{}
	_ = b[2:]
}

gotype says:

x.go:5:8: index 2 (constant of type int) is out of bounds

cmd/compile gives no error. If you change b's type to [1]struct{}, the error from cmd/compile is:

x.go:5: invalid slice index 2 (out of bounds for 1-element array)

Reproduces with (at least) 1.7 and 1.8 and 1.9beta1.

@josharian josharian added this to the Go1.10 milestone Jun 22, 2017
@josharian
Copy link
Contributor Author

Found with go-fuzz.

@ianlancetaylor
Copy link
Contributor

gccgo says

foo8.go:5:8: error: array index out of bounds
  _ = b[2:]
        ^

@griesemer
Copy link
Contributor

This is clearly a cmp/compile bug. Interestingly, the compiler complains for an index expression (b[2]) rather than a slice expression (b[2:]).

@griesemer griesemer self-assigned this Jun 22, 2017
@griesemer
Copy link
Contributor

Trivial fix. Moving to 1.9.

@griesemer griesemer modified the milestones: Go1.9, Go1.10 Jun 22, 2017
@gopherbot
Copy link

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

@golang golang locked and limited conversation to collaborators Jun 22, 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

4 participants