Skip to content

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

Closed

Description

@josharian
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.

Activity

  1. added this to the Go1.10 milestone on Jun 22, 2017
  2. josharian commented on Jun 22, 2017

    @josharian
    ContributorAuthor

    Found with go-fuzz.

  3. ianlancetaylor commented on Jun 22, 2017

    @ianlancetaylor
    Contributor

    gccgo says

    foo8.go:5:8: error: array index out of bounds
      _ = b[2:]
            ^
    
  4. griesemer commented on Jun 22, 2017

    @griesemer
    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:]).

  5. self-assigned this
    on Jun 22, 2017
  6. griesemer commented on Jun 22, 2017

    @griesemer
    Contributor

    Trivial fix. Moving to 1.9.

  7. modified the milestones: Go1.9, Go1.10 on Jun 22, 2017
  8. gopherbot commented on Jun 22, 2017

    @gopherbot
    Contributor

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

  9. locked and limited conversation to collaborators on Jun 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions