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

Comments

Projects
None yet
4 participants
@josharian
Copy link
Contributor

commented Jun 22, 2017

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

This comment has been minimized.

Copy link
Contributor Author

commented Jun 22, 2017

Found with go-fuzz.

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Jun 22, 2017

gccgo says

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

This comment has been minimized.

Copy link
Contributor

commented Jun 22, 2017

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

This comment has been minimized.

Copy link
Contributor

commented Jun 22, 2017

Trivial fix. Moving to 1.9.

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

@gopherbot

This comment has been minimized.

Copy link

commented Jun 22, 2017

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

@gopherbot gopherbot closed this in 47e659b Jun 22, 2017

@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.
You can’t perform that action at this time.