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:
parent
5b55a71008
commit
27b698bc2a
|
@ -286,7 +286,11 @@ func (check *checker) selector(x *operand, e *ast.SelectorExpr) {
|
||||||
switch obj := obj.(type) {
|
switch obj := obj.(type) {
|
||||||
case *Var:
|
case *Var:
|
||||||
check.recordSelection(e, FieldVal, x.typ, obj, index, indirect)
|
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
|
x.typ = obj.typ
|
||||||
|
|
||||||
case *Func:
|
case *Func:
|
||||||
|
|
|
@ -92,6 +92,21 @@ func assignments1() {
|
||||||
(_) = 0
|
(_) = 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() {
|
func shortVarDecls() {
|
||||||
const c = 0
|
const c = 0
|
||||||
type d int
|
type d int
|
||||||
|
|
Loading…
Reference in New Issue