1
0
mirror of https://github.com/golang/go synced 2024-09-24 17:20:12 -06:00

spec: only require parens around ambiguous conversions

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
This commit is contained in:
Russ Cox 2013-02-11 07:48:14 -05:00
parent 7576179aa3
commit 71c941b6f6

View 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>