mirror of
https://github.com/golang/go
synced 2024-11-25 14:47:57 -07: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:
parent
7576179aa3
commit
71c941b6f6
@ -3448,16 +3448,20 @@ Conversion = Type "(" Expression [ "," ] ")" .
|
|||||||
|
|
||||||
<p>
|
<p>
|
||||||
If the type starts with the operator <code>*</code> or <code><-</code>,
|
If the type starts with the operator <code>*</code> or <code><-</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>
|
</p>
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
*Point(p) // same as *(Point(p))
|
*Point(p) // same as *(Point(p))
|
||||||
(*Point)(p) // p is converted to (*Point)
|
(*Point)(p) // p is converted to *Point
|
||||||
<-chan int(c) // same as <-(chan int(c))
|
<-chan int(c) // same as <-(chan int(c))
|
||||||
(<-chan int)(c) // c is converted to (<-chan int)
|
(<-chan int)(c) // c is converted to <-chan int
|
||||||
func()(x) // function signature func() x
|
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>
|
</pre>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
@ -3553,12 +3557,6 @@ implements this functionality under
|
|||||||
restricted circumstances.
|
restricted circumstances.
|
||||||
</p>
|
</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>
|
<h4>Conversions between numeric types</h4>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
Loading…
Reference in New Issue
Block a user