go.tools/go/types: address and slice operations are not addressable
LGTM=gri R=gri CC=golang-codereviews https://golang.org/cl/89380044
This commit is contained in:
parent
998b73a2e9
commit
feafa74756
|
@ -84,14 +84,12 @@ func (check *checker) unary(x *operand, op token.Token) {
|
|||
case token.AND:
|
||||
// spec: "As an exception to the addressability
|
||||
// requirement x may also be a composite literal."
|
||||
if _, ok := unparen(x.expr).(*ast.CompositeLit); ok {
|
||||
x.mode = variable
|
||||
}
|
||||
if x.mode != variable {
|
||||
if _, ok := unparen(x.expr).(*ast.CompositeLit); !ok && x.mode != variable {
|
||||
check.invalidOp(x.pos(), "cannot take address of %s", x)
|
||||
x.mode = invalid
|
||||
return
|
||||
}
|
||||
x.mode = value
|
||||
x.typ = &Pointer{base: x.typ}
|
||||
return
|
||||
|
||||
|
@ -1228,7 +1226,6 @@ func (check *checker) exprInternal(x *operand, e ast.Expr, hint Type) exprKind {
|
|||
}
|
||||
// spec: "For untyped string operands the result
|
||||
// is a non-constant value of type string."
|
||||
x.mode = value
|
||||
if typ.kind == UntypedString {
|
||||
x.typ = Typ[String]
|
||||
}
|
||||
|
@ -1247,13 +1244,11 @@ func (check *checker) exprInternal(x *operand, e ast.Expr, hint Type) exprKind {
|
|||
if typ, _ := typ.base.Underlying().(*Array); typ != nil {
|
||||
valid = true
|
||||
length = typ.len
|
||||
x.mode = variable
|
||||
x.typ = &Slice{elem: typ.elem}
|
||||
}
|
||||
|
||||
case *Slice:
|
||||
valid = true
|
||||
x.mode = variable
|
||||
// x.typ doesn't change
|
||||
}
|
||||
|
||||
|
@ -1262,6 +1257,8 @@ func (check *checker) exprInternal(x *operand, e ast.Expr, hint Type) exprKind {
|
|||
goto Error
|
||||
}
|
||||
|
||||
x.mode = value
|
||||
|
||||
// spec: "Only the first index may be omitted; it defaults to 0."
|
||||
if slice3(e) && (e.High == nil || sliceMax(e) == nil) {
|
||||
check.error(e.Rbrack, "2nd and 3rd index required in 3-index slice")
|
||||
|
|
|
@ -21,6 +21,7 @@ var (
|
|||
b10 = &true /* ERROR "cannot take address" */
|
||||
b11 = &b0
|
||||
b12 = <-b0 /* ERROR "cannot receive" */
|
||||
b13 = & & /* ERROR "cannot take address" */ b0
|
||||
|
||||
// int
|
||||
i0 = 1
|
||||
|
|
|
@ -44,6 +44,7 @@ func indexes() {
|
|||
_ = a[10:0:10] /* ERROR "invalid slice indices" */
|
||||
_ = a[0:10:0] /* ERROR "invalid slice indices" */
|
||||
_ = a[10:0:0] /* ERROR "invalid slice indices" */
|
||||
_ = &a /* ERROR "cannot take address" */ [:10]
|
||||
|
||||
pa := &a
|
||||
_ = pa[9]
|
||||
|
@ -61,6 +62,7 @@ func indexes() {
|
|||
_ = pa[10:0:10] /* ERROR "invalid slice indices" */
|
||||
_ = pa[0:10:0] /* ERROR "invalid slice indices" */
|
||||
_ = pa[10:0:0] /* ERROR "invalid slice indices" */
|
||||
_ = &pa /* ERROR "cannot take address" */ [:10]
|
||||
|
||||
var b [0]int
|
||||
_ = b[0 /* ERROR "index .* out of bounds" */ ]
|
||||
|
@ -87,6 +89,7 @@ func indexes() {
|
|||
_ = s[10:0:10] /* ERROR "invalid slice indices" */
|
||||
_ = s[0:10:0] /* ERROR "invalid slice indices" */
|
||||
_ = s[10:0:0] /* ERROR "invalid slice indices" */
|
||||
_ = &s /* ERROR "cannot take address" */ [:10]
|
||||
|
||||
var t string
|
||||
_ = t[- /* ERROR "negative" */ 1]
|
||||
|
|
Loading…
Reference in New Issue