]> Cypherpunks repositories - gostls13.git/commitdiff
go spec: adjust notion of Assignability
authorRobert Griesemer <gri@golang.org>
Thu, 3 Feb 2011 18:53:31 +0000 (10:53 -0800)
committerRobert Griesemer <gri@golang.org>
Thu, 3 Feb 2011 18:53:31 +0000 (10:53 -0800)
This change makes it legal to pass a struct value as receiver
outside the package declaring the struct even if the respective
struct type has non-exported fields.

This is a backwards-compatible language change motivated by the
fact that it is already possible to circumvent the assignment
restriction when calling methods through interfaces (see issue
1402).

R=r, rsc, iant, ken2
CC=golang-dev
https://golang.org/cl/3926044

doc/go_spec.html

index a861f0cbf66870e592041b2e1b0fe251a842f57d..047710b6cf527eda043d77e4424013b153778590 100644 (file)
@@ -1349,11 +1349,12 @@ by a value of type <code>T</code>.
 </ul>
 
 <p>
-If <code>T</code> is a struct type, either all fields of <code>T</code>
-must be <a href="#Exported_identifiers">exported</a>, or the assignment must be in
-the same package in which <code>T</code> is declared.
+If <code>T</code> is a struct type with non-<a href="#Exported_identifiers">exported</a>
+fields, the assignment must be in the same package in which <code>T</code> is declared,
+or <code>x</code> must be the receiver of a method call.
 In other words, a struct value can be assigned to a struct variable only if
-every field of the struct may be legally assigned individually by the program.
+every field of the struct may be legally assigned individually by the program,
+or if the assignment is initializing the receiver of a method of the struct type.
 </p>
 
 <p>