mirror of
https://github.com/golang/go
synced 2024-11-18 18:04:46 -07:00
go.tools/go/types: fix build for Go 1.1 users
Fixes golang/go#6485. R=gri CC=golang-dev https://golang.org/cl/13901045
This commit is contained in:
parent
d7287a0289
commit
577fe73c91
@ -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:
|
||||
|
17
go/types/go11.go
Normal file
17
go/types/go11.go
Normal file
@ -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
go/types/go12.go
Normal file
17
go/types/go12.go
Normal file
@ -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
|
||||
}
|
Loading…
Reference in New Issue
Block a user