From 3b0224282cf84228d6bcd4b783eb164e579fbd9e Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Fri, 11 Sep 2015 16:20:23 -0700 Subject: [PATCH] spec: fix composite literal syntax to match prose Fixes #12578. Change-Id: I257d70a67609463e24936bc1739285da154be2fe Reviewed-on: https://go-review.googlesource.com/14531 Reviewed-by: Rob Pike --- doc/go_spec.html | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/doc/go_spec.html b/doc/go_spec.html index 22f9701a75..7de0c7b716 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,6 +1,6 @@ @@ -2210,9 +2210,8 @@ math.Sin // denotes the Sin function in package math

Composite literals construct values for structs, arrays, slices, and maps and create a new value each time they are evaluated. -They consist of the type of the value -followed by a brace-bound list of composite elements. An element may be -a single expression or a key-value pair. +They consist of the type of the value followed by a brace-bound list of elements. +Each element may optionally be preceded by a corresponding key.

@@ -2220,18 +2219,18 @@ CompositeLit  = LiteralType LiteralValue .
 LiteralType   = StructType | ArrayType | "[" "..." "]" ElementType |
                 SliceType | MapType | TypeName .
 LiteralValue  = "{" [ ElementList [ "," ] ] "}" .
-ElementList   = Element { "," Element } .
-Element       = [ Key ":" ] Value .
+ElementList   = KeyedElement { "," KeyedElement } .
+KeyedElement  = [ Key ":" ] Element .
 Key           = FieldName | Expression | LiteralValue .
 FieldName     = identifier .
-Value         = Expression | LiteralValue .
+Element       = Expression | LiteralValue .
 

The LiteralType must be a struct, array, slice, or map type (the grammar enforces this constraint except when the type is given as a TypeName). -The types of the expressions must be assignable +The types of the elements and keys must be assignable to the respective field, element, and key types of the LiteralType; there is no additional conversion. The key is interpreted as a field name for struct literals, -- 2.48.1