diff --git a/go/types/call.go b/go/types/call.go index d57172f0..ebfd00de 100644 --- a/go/types/call.go +++ b/go/types/call.go @@ -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: diff --git a/go/types/testdata/stmt0.src b/go/types/testdata/stmt0.src index 393af5d6..c60e0508 100644 --- a/go/types/testdata/stmt0.src +++ b/go/types/testdata/stmt0.src @@ -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