mirror of
https://github.com/golang/go
synced 2024-09-05 16:04:50 +00:00
go spec: adjust notion of Assignability
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
This commit is contained in:
parent
ab15a978fb
commit
fa3d0d73f0
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue