From fa3d0d73f0e0559f63dd14d09fc167c89df9fe54 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Thu, 3 Feb 2011 10:53:31 -0800 Subject: [PATCH] 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 --- doc/go_spec.html | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/doc/go_spec.html b/doc/go_spec.html index a861f0cbf6..047710b6cf 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1349,11 +1349,12 @@ by a value of type T.

-If T is a struct type, either all fields of T -must be exported, or the assignment must be in -the same package in which T is declared. +If T is a struct type with non-exported +fields, the assignment must be in the same package in which T is declared, +or x 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.