From d3b1565716ddbd7114d0dbb2b59fc6bd900ea85e Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Mon, 16 Nov 2009 08:58:55 -0800 Subject: [PATCH] - Clarify that struct composite literal keys are field names not selectors. - Slight re-phrasing of struct type section since "field name" was not properly introduced. Fixes #164. R=r, rsc, iant https://golang.org/cl/155061 --- doc/go_spec.html | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/doc/go_spec.html b/doc/go_spec.html index cba73ce8364..b5e20bcaa55 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -694,17 +694,19 @@ new([100]int)[0:50]

Struct types

-A struct is a sequence of named -elements, called fields, with various types. A struct type declares -an identifier and type for each field. Within a struct, non-blank -field identifiers must be unique. +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). +Within a struct, non-blank field names must +be unique.

-StructType = "struct" "{" [ FieldDeclList ] "}" .
-FieldDeclList = FieldDecl { ";" FieldDecl } [ ";" ] .
-FieldDecl = (IdentifierList Type | [ "*" ] TypeName) [ Tag ] .
-Tag = StringLit .
+StructType     = "struct" "{" [ FieldDeclList ] "}" .
+FieldDeclList  = FieldDecl { ";" FieldDecl } [ ";" ] .
+FieldDecl      = (IdentifierList Type | AnonymousField) [ Tag ] .
+AnonymousField = [ "*" ] TypeName .
+Tag            = StringLit .
 
@@ -722,28 +724,27 @@ struct {
 

-A field declared with a type but no field identifier is an anonymous field. +A field declared with a type but no explicit field name is an anonymous field. Such a field type must be specified as a type name T or as a pointer to a type name *T, and T itself may not be -a pointer type. The unqualified type name acts as the field identifier. +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
 struct {
-	T1;        // the field name is T1
-	*T2;       // the field name is T2
-	P.T3;      // the field name is T3
-	*P.T4;     // the field name is T4
-	x, y int;
+	T1;        // field name is T1
+	*T2;       // field name is T2
+	P.T3;      // field name is T3
+	*P.T4;     // field name is T4
+	x, y int;  // field names are x and y
 }
 

-The unqualified type name of an anonymous field must be distinct from the -field identifier (or unqualified type name for an anonymous field) of every -other field within the struct. The following declaration is illegal: +The following declaration is illegal because field names must be unique +in a struct type:

@@ -778,7 +779,7 @@ a type named T:
 
 

A field declaration may be followed by an optional string literal tag, -which becomes an attribute for all the identifiers in the corresponding +which becomes an attribute for all the fields in the corresponding field declaration. The tags are made visible through a reflection interface but are otherwise ignored. @@ -1915,6 +1916,8 @@ constant key value. For struct literals the following rules apply: