From 8e38b17a906e7208fe9133cedd154758ae4f717d Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 29 Feb 2012 15:54:06 -0500 Subject: [PATCH] spec: apply method sets, embedding to all types, not just named types When we first wrote the method set definition, we had long discussions about whether method sets applied to all types or just named types, and we (or at least I) concluded that it didn't matter: the two were equivalent points of view, because the only way to introduce a new method was to write a method function, which requires a named receiver type. However, the addition of embedded types changed this. Embedding can introduce a method without writing an explicit method function, as in: var x struct { sync.Mutex } var px *struct { sync.Mutex } var _, _ sync.Locker = &x, px The edits in this CL make clear that both &x and px satisfy sync.Locker. Today, gccgo already works this way; 6g does not. R=golang-dev, gri, iant, r CC=golang-dev https://golang.org/cl/5702062 --- doc/go_spec.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/go_spec.html b/doc/go_spec.html index f0aac6b141..ae0a4616a7 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -678,7 +678,7 @@ and T4 is []T1. A type may have a method set associated with it (§Interface types, §Method declarations). The method set of an interface type is its interface. -The method set of any other named type T +The method set of any other type T consists of all methods with receiver type T. The method set of the corresponding pointer type *T is the set of all methods with receiver *T or T @@ -954,7 +954,7 @@ struct {

Fields and methods (§Method declarations) of an anonymous field are promoted to be ordinary fields and methods of the struct (§Selectors). -The following rules apply for a struct type named S and +The following rules apply for a struct type S and a type named T: