Skip to content

Commit

Permalink
go.tools/go/types: fix build for Go 1.1 users
Browse files Browse the repository at this point in the history
  • Loading branch information
rsc committed Sep 26, 2013
1 parent d7287a0 commit 577fe73
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
6 changes: 3 additions & 3 deletions go/types/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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:
Expand Down
17 changes: 17 additions & 0 deletions go/types/go11.go
Original file line number Diff line number Diff line change
@@ -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
}
17 changes: 17 additions & 0 deletions go/types/go12.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 577fe73

Please sign in to comment.