Commit 71c941b6 authored by Russ Cox's avatar Russ Cox

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
parent 7576179a
......@@ -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>
......
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