diff options
author | Russ Cox <rsc@golang.org> | 2011-11-15 12:20:59 -0500 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2011-11-15 12:20:59 -0500 |
commit | 0460aef11c000474b6c374a0cd5ee01d67e2d9bb (patch) | |
tree | cda31fd0be4cf37e2b310a8d27dbceefc6fe9a53 /test/assign.go | |
parent | 6ee7f0dbfdde410b963fd7980cdacb70604c9f1b (diff) | |
download | go-0460aef11c000474b6c374a0cd5ee01d67e2d9bb.tar.gz |
allow copy of struct containing unexported fields
An experiment: allow structs to be copied even if they
contain unexported fields. This gives packages the
ability to return opaque values in their APIs, like reflect
does for reflect.Value but without the kludgy hacks reflect
resorts to.
In general, we trust programmers not to do silly things
like *x = *y on a package's struct pointers, just as we trust
programmers not to do unicode.Letter = unicode.Digit,
but packages that want a harder guarantee can introduce
an extra level of indirection, like in the changes to os.File
in this CL or by using an interface type.
All in one CL so that it can be rolled back more easily if
we decide this is a bad idea.
Originally discussed in March 2011.
https://groups.google.com/group/golang-dev/t/3f5d30938c7c45ef
R=golang-dev, adg, dvyukov, r, bradfitz, jan.mercl, gri
CC=golang-dev
http://codereview.appspot.com/5372095
Diffstat (limited to 'test/assign.go')
-rw-r--r-- | test/assign.go | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/test/assign.go b/test/assign.go index 59471388c..2192f9ede 100644 --- a/test/assign.go +++ b/test/assign.go @@ -16,38 +16,38 @@ type T struct { func main() { { var x, y sync.Mutex - x = y // ERROR "assignment.*Mutex" + x = y // ok _ = x } { var x, y T - x = y // ERROR "assignment.*Mutex" + x = y // ok _ = x } { var x, y [2]sync.Mutex - x = y // ERROR "assignment.*Mutex" + x = y // ok _ = x } { var x, y [2]T - x = y // ERROR "assignment.*Mutex" + x = y // ok _ = x } { - x := sync.Mutex{0, 0} // ERROR "assignment.*Mutex" + x := sync.Mutex{0, 0} // ERROR "assignment.*Mutex" _ = x } { - x := sync.Mutex{key: 0} // ERROR "(unknown|assignment).*Mutex" + x := sync.Mutex{key: 0} // ERROR "(unknown|assignment).*Mutex" _ = x } { - x := &sync.Mutex{} // ok - var y sync.Mutex // ok - y = *x // ERROR "assignment.*Mutex" - *x = y // ERROR "assignment.*Mutex" + x := &sync.Mutex{} // ok + var y sync.Mutex // ok + y = *x // ok + *x = y // ok _ = x _ = y - } + } } |