From f8b4123613a2cb0c453726033a03a1968205ccae Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Tue, 10 Jan 2017 16:19:14 -0800 Subject: [PATCH] [dev.typealias] spec: use term 'embedded field' rather than 'anonymous field' First steps towards defining type aliases in the spec. This is a nomenclature clarification, not a language change. The spec used all three terms 'embedded type', 'anonymous field', and 'embedded field'. Users where using the terms inconsistently. The notion of an 'anonymous' field was always misleading since they always had a de-facto name. With type aliases that name becomes even more important because we may have different names for the same type. Use the term 'embedded field' consistently and remove competing terminology. For #18130. Change-Id: I2083bbc85788cab0b2e2cb1ff58b2f979491f001 Reviewed-on: https://go-review.googlesource.com/35108 Reviewed-by: Alan Donovan Reviewed-by: Russ Cox Reviewed-by: Rob Pike --- doc/go_spec.html | 50 ++++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/doc/go_spec.html b/doc/go_spec.html index 5872eefb03f3d..c71126d25d8dd 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,6 +1,6 @@ @@ -738,7 +738,7 @@

Method sets

The method set of the corresponding pointer type *T is the set of all methods declared with receiver *T or T (that is, it also contains the method set of T). -Further rules apply to structs containing anonymous fields, as described +Further rules apply to structs containing embedded fields, as described in the section on struct types. Any other type has an empty method set. In a method set, each method must have a @@ -947,16 +947,16 @@

Struct types

A struct is a sequence of named elements, called fields, each of which has a name and a type. Field names may be specified explicitly (IdentifierList) or -implicitly (AnonymousField). +implicitly (EmbeddedField). Within a struct, non-blank field names must be unique.

-StructType     = "struct" "{" { FieldDecl ";" } "}" .
-FieldDecl      = (IdentifierList Type | AnonymousField) [ Tag ] .
-AnonymousField = [ "*" ] TypeName .
-Tag            = string_lit .
+StructType    = "struct" "{" { FieldDecl ";" } "}" .
+FieldDecl     = (IdentifierList Type | EmbeddedField) [ Tag ] .
+EmbeddedField = [ "*" ] TypeName .
+Tag           = string_lit .
 
@@ -974,16 +974,15 @@ 

Struct types

-A field declared with a type but no explicit field name is an anonymous field, -also called an embedded field or an embedding of the type in the struct. -An embedded type must be specified as +A field declared with a type but no explicit field name is called an embedded field. +An embedded field must be specified as a type name T or as a pointer to a non-interface type name *T, and T itself may not be a pointer type. The unqualified type name acts as the field name.

-// A struct with four anonymous fields of type T1, *T2, P.T3 and *P.T4
+// A struct with four embedded fields of types T1, *T2, P.T3 and *P.T4
 struct {
 	T1        // field name is T1
 	*T2       // field name is T2
@@ -1000,15 +999,15 @@ 

Struct types

 struct {
-	T     // conflicts with anonymous field *T and *P.T
-	*T    // conflicts with anonymous field T and *P.T
-	*P.T  // conflicts with anonymous field T and *T
+	T     // conflicts with embedded field *T and *P.T
+	*T    // conflicts with embedded field T and *P.T
+	*P.T  // conflicts with embedded field T and *T
 }
 

A field or method f of an -anonymous field in a struct x is called promoted if +embedded field in a struct x is called promoted if x.f is a legal selector that denotes that field or method f.

@@ -1025,7 +1024,7 @@

Struct types

  • - If S contains an anonymous field T, + If S contains an embedded field T, the method sets of S and *S both include promoted methods with receiver T. The method set of *S also @@ -1033,7 +1032,7 @@

    Struct types

  • - If S contains an anonymous field *T, + If S contains an embedded field *T, the method sets of S and *S both include promoted methods with receiver T or *T. @@ -1434,8 +1433,8 @@

    Type identity

  • Two struct types are identical if they have the same sequence of fields, and if corresponding fields have the same names, and identical types, and identical tags. - Two anonymous fields are considered to have the same name. Lower-case field - names from different packages are always different.
  • + Non-exported field names from different + packages are always different.
  • Two pointer types are identical if they have identical base types.
  • @@ -1445,8 +1444,9 @@

    Type identity

    Parameter and result names are not required to match.
  • Two interface types are identical if they have the same set of methods - with the same names and identical function types. Lower-case method names from - different packages are always different. The order of the methods is irrelevant.
  • + with the same names and identical function types. + Non-exported method names from different + packages are always different. The order of the methods is irrelevant.
  • Two map types are identical if they have identical key and value types.
  • @@ -1891,7 +1891,7 @@

    Type declarations

    type PtrMutex *Mutex // The method set of *PrintableMutex contains the methods -// Lock and Unlock bound to its anonymous field Mutex. +// Lock and Unlock bound to its embedded field Mutex. type PrintableMutex struct { Mutex } @@ -2492,13 +2492,13 @@

    Selectors

    A selector f may denote a field or method f of a type T, or it may refer to a field or method f of a nested -anonymous field of T. -The number of anonymous fields traversed +embedded field of T. +The number of embedded fields traversed to reach f is called its depth in T. The depth of a field or method f declared in T is zero. The depth of a field or method f declared in -an anonymous field A in T is the +an embedded field A in T is the depth of f in A plus one.