Skip to content

Commit

Permalink
go/parser: accept optional indices for all parts of an index expression
Browse files Browse the repository at this point in the history
Instead, leave the error testing to the type checker, eventually.

Fixes #5827.

R=adonovan
CC=golang-dev
https://golang.org/cl/10917043
  • Loading branch information
griesemer committed Jul 3, 2013
1 parent 16c3f82 commit dd1fe82
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 10 deletions.
4 changes: 0 additions & 4 deletions src/pkg/go/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -1187,10 +1187,6 @@ func (p *parser) parseIndexOrSlice(x ast.Expr) ast.Expr {

if ncolons > 0 {
// slice expression
if ncolons == 2 && (index[1] == nil || index[2] == nil) {
// only i is optional in a[i:j:k]
p.error(rbrack, "2nd and 3rd index must be present full slice expression")
}
return &ast.SliceExpr{X: x, Lbrack: lbrack, Low: index[0], High: index[1], Max: index[2], Rbrack: rbrack}
}

Expand Down
6 changes: 0 additions & 6 deletions src/pkg/go/parser/short_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,6 @@ var invalids = []string{
`package p; func f() { var s []int; _ = s[] /* ERROR "expected operand" */ };`,
`package p; func f() { var s []int; _ = s[::: /* ERROR "expected ']'" */ ] };`,
`package p; func f() { var s []int; _ = s[i:j:k: /* ERROR "expected ']'" */ l] };`,
`package p; func f() { var s []int; g(s[::] /* ERROR "index must be present" */) };`,
`package p; func f() { var s []int; g(s[i::] /* ERROR "index must be present" */) };`,
`package p; func f() { var s []int; g(s[i:j:] /* ERROR "index must be present" */) };`,
`package p; func f() { var s []int; g(s[::k] /* ERROR "index must be present" */) };`,
`package p; func f() { var s []int; g(s[:j:] /* ERROR "index must be present" */) };`,
`package p; func f() { var s []int; g(s[i::k] /* ERROR "index must be present" */) };`,
}

func TestInvalid(t *testing.T) {
Expand Down

0 comments on commit dd1fe82

Please sign in to comment.