Commit a36b5b99 authored by Robert Griesemer's avatar Robert Griesemer

spec: slightly rephrased wording on parsing ambiguity for composite literals

Fixes #4482.

LGTM=r
R=r, iant, rsc, ken
CC=golang-codereviews
https://golang.org/cl/69020045
parent 7e0dac08
<!--{ <!--{
"Title": "The Go Programming Language Specification", "Title": "The Go Programming Language Specification",
"Subtitle": "Version of Feb 25, 2014", "Subtitle": "Version of Feb 27, 2014",
"Path": "/ref/spec" "Path": "/ref/spec"
}--> }-->
...@@ -2267,8 +2267,6 @@ Similarly, elements that are addresses of composite literals may elide ...@@ -2267,8 +2267,6 @@ Similarly, elements that are addresses of composite literals may elide
the <code>&amp;T</code> when the element type is <code>*T</code>. the <code>&amp;T</code> when the element type is <code>*T</code>.
</p> </p>
<pre> <pre>
[...]Point{{1.5, -3.5}, {0, 0}} // same as [...]Point{Point{1.5, -3.5}, Point{0, 0}} [...]Point{{1.5, -3.5}, {0, 0}} // same as [...]Point{Point{1.5, -3.5}, Point{0, 0}}
[][]int{{1, 2, 3}, {4, 5}} // same as [][]int{[]int{1, 2, 3}, []int{4, 5}} [][]int{{1, 2, 3}, {4, 5}} // same as [][]int{[]int{1, 2, 3}, []int{4, 5}}
...@@ -2278,13 +2276,13 @@ the <code>&amp;T</code> when the element type is <code>*T</code>. ...@@ -2278,13 +2276,13 @@ the <code>&amp;T</code> when the element type is <code>*T</code>.
<p> <p>
A parsing ambiguity arises when a composite literal using the A parsing ambiguity arises when a composite literal using the
TypeName form of the LiteralType appears between the TypeName form of the LiteralType appears as an operand between the
<a href="#Keywords">keyword</a> and the opening brace of the block of an <a href="#Keywords">keyword</a> and the opening brace of the block
"if", "for", or "switch" statement, because the braces surrounding of an "if", "for", or "switch" statement, and the composite literal
the expressions in the literal are confused with those introducing is not enclosed in parentheses, square brackets, or curly braces.
the block of statements. To resolve the ambiguity in this rare case, In this rare case, the opening brace of the literal is erroneously parsed
the composite literal must appear within as the one introducing the block of statements. To resolve the ambiguity,
parentheses. the composite literal must appear within parentheses.
</p> </p>
<pre> <pre>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment