]> Cypherpunks repositories - gostls13.git/commit
allow copy of struct containing unexported fields
authorRuss Cox <rsc@golang.org>
Tue, 15 Nov 2011 17:20:59 +0000 (12:20 -0500)
committerRuss Cox <rsc@golang.org>
Tue, 15 Nov 2011 17:20:59 +0000 (12:20 -0500)
commitd03611f628c65321b572ab0d4ce85cc61b759fc6
tree4e96b7a4c4fc5d4c9a18cba4566bd8b6a874d703
parent0ed5e6a2be4c7248dfb6c870c445e2504f818623
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
https://golang.org/cl/5372095
15 files changed:
doc/go_spec.html
src/cmd/gc/go.h
src/cmd/gc/subr.c
src/cmd/gc/typecheck.c
src/pkg/os/file_plan9.go
src/pkg/os/file_unix.go
src/pkg/os/file_windows.go
src/pkg/sync/mutex.go
test/assign.go
test/fixedbugs/bug226.dir/x.go [deleted file]
test/fixedbugs/bug226.dir/y.go [deleted file]
test/fixedbugs/bug226.go [deleted file]
test/fixedbugs/bug310.go [deleted file]
test/fixedbugs/bug359.go [deleted file]
test/fixedbugs/bug378.go [deleted file]