diff --git a/go/types/expr.go b/go/types/expr.go index cae9c2f6..d75298ba 100644 --- a/go/types/expr.go +++ b/go/types/expr.go @@ -1166,7 +1166,7 @@ func (check *checker) expr0(x *operand, e ast.Expr, hint Type) exprKind { switch typ := x.typ.Underlying().(type) { case *Basic: if isString(typ) { - if e.Slice3 { + if slice3(e) { check.invalidOp(x.pos(), "3-index slice of string") goto Error } @@ -1211,14 +1211,14 @@ func (check *checker) expr0(x *operand, e ast.Expr, hint Type) exprKind { } // spec: "Only the first index may be omitted; it defaults to 0." - if e.Slice3 && (e.High == nil || e.Max == nil) { + if slice3(e) && (e.High == nil || sliceMax(e) == nil) { check.errorf(e.Rbrack, "2nd and 3rd index required in 3-index slice") goto Error } // check indices var ind [3]int64 - for i, expr := range []ast.Expr{e.Low, e.High, e.Max} { + for i, expr := range []ast.Expr{e.Low, e.High, sliceMax(e)} { x := int64(-1) switch { case expr != nil: diff --git a/go/types/go11.go b/go/types/go11.go new file mode 100644 index 00000000..cf41cabe --- /dev/null +++ b/go/types/go11.go @@ -0,0 +1,17 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build !go1.2 + +package types + +import "go/ast" + +func slice3(x *ast.SliceExpr) bool { + return false +} + +func sliceMax(x *ast.SliceExpr) ast.Expr { + return nil +} diff --git a/go/types/go12.go b/go/types/go12.go new file mode 100644 index 00000000..20174421 --- /dev/null +++ b/go/types/go12.go @@ -0,0 +1,17 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build go1.2 + +package types + +import "go/ast" + +func slice3(x *ast.SliceExpr) bool { + return x.Slice3 +} + +func sliceMax(x *ast.SliceExpr) ast.Expr { + return x.Max +}