go.tools/go/types: x.f is addressable if x is addressable or x.f contains an indirection

Fixes golang/go#6487.

R=adonovan
CC=golang-dev
https://golang.org/cl/14047043
This commit is contained in:
Robert Griesemer 2013-09-27 09:33:00 -07:00
parent 5b55a71008
commit 27b698bc2a
2 changed files with 20 additions and 1 deletions

View File

@ -286,7 +286,11 @@ func (check *checker) selector(x *operand, e *ast.SelectorExpr) {
switch obj := obj.(type) {
case *Var:
check.recordSelection(e, FieldVal, x.typ, obj, index, indirect)
x.mode = variable
if x.mode == variable || indirect {
x.mode = variable
} else {
x.mode = value
}
x.typ = obj.typ
case *Func:

View File

@ -92,6 +92,21 @@ func assignments1() {
(_) = 0
}
func issue6487() {
type S struct{x int}
_ = &S /* ERROR "cannot take address" */ {}.x
_ = &( /* ERROR "cannot take address" */ S{}.x)
_ = (&S{}).x
S /* ERROR "cannot assign" */ {}.x = 0
(&S{}).x = 0
type M map[string]S
var m M
m /* ERROR "cannot assign" */ ["foo"].x = 0
_ = &( /* ERROR "cannot take address" */ m["foo"].x)
_ = &m /* ERROR "cannot take address" */ ["foo"].x
}
func shortVarDecls() {
const c = 0
type d int