aboutsummaryrefslogtreecommitdiff
path: root/test/assign.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2011-11-15 12:20:59 -0500
committerRuss Cox <rsc@golang.org>2011-11-15 12:20:59 -0500
commitd03611f628c65321b572ab0d4ce85cc61b759fc6 (patch)
tree4e96b7a4c4fc5d4c9a18cba4566bd8b6a874d703 /test/assign.go
parent0ed5e6a2be4c7248dfb6c870c445e2504f818623 (diff)
downloadgo-d03611f628c65321b572ab0d4ce85cc61b759fc6.tar.gz
go-d03611f628c65321b572ab0d4ce85cc61b759fc6.zip
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
Diffstat (limited to 'test/assign.go')
-rw-r--r--test/assign.go22
1 files changed, 11 insertions, 11 deletions
diff --git a/test/assign.go b/test/assign.go
index 59471388c0..2192f9ede0 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
- }
+ }
}