]> Cypherpunks repositories - gostls13.git/commitdiff
spec: only require parens around ambiguous conversions
authorRuss Cox <rsc@golang.org>
Mon, 11 Feb 2013 12:48:14 +0000 (07:48 -0500)
committerRuss Cox <rsc@golang.org>
Mon, 11 Feb 2013 12:48:14 +0000 (07:48 -0500)
This is documenting the status quo. The previous cleanup
added this language as an implementation restriction, but
at least for now it is really part of the language proper.

Fixes #4605.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/7305071

doc/go_spec.html

index 246a3656ad3e0d2250bb9e8cc75be96116b4bb8c..5f84a296452ed8651327f0c52a5cd7e73224ba7a 100644 (file)
@@ -3448,16 +3448,20 @@ Conversion = Type "(" Expression [ "," ] ")" .
 
 <p>
 If the type starts with the operator <code>*</code> or <code>&lt;-</code>,
-or the keyword <code>func</code>, it must be parenthesized:
+or if the type starts with the keyword <code>func</code>
+and has no result list, it must be parenthesized when
+necessary to avoid ambiguity:
 </p>
 
 <pre>
 *Point(p)        // same as *(Point(p))
-(*Point)(p)      // p is converted to (*Point)
+(*Point)(p)      // p is converted to *Point
 &lt;-chan int(c)    // same as &lt;-(chan int(c))
-(&lt;-chan int)(c)  // c is converted to (&lt;-chan int)
+(&lt;-chan int)(c)  // c is converted to &lt;-chan int
 func()(x)        // function signature func() x
-(func())(x)      // x is converted to (func())
+(func())(x)      // x is converted to func()
+(func() int)(x)  // x is converted to func() int
+func() int(x)    // x is converted to func() int (unambiguous)
 </pre>
 
 <p>
@@ -3553,12 +3557,6 @@ implements this functionality under
 restricted circumstances.
 </p>
 
-<p>
-Implementation restriction: For backward-compatibility with the Go 1 language
-specification, a compiler may accept non-parenthesized literal function types
-in conversions where the syntax is unambiguous.
-</p>
-
 <h4>Conversions between numeric types</h4>
 
 <p>