mirror of https://github.com/golang/go.git
go spec: conversion types starting with "func" must be parenthesized
Also: Be explicit what operator means with respect to conversion types.
The parenthesis requirement is a language change. At the moment,
literal function types in conversions that cannot possibly be
followed by a '(' don't need parentheses. For instance:
func(int)int(x) -> same as (func(int)int)(x)
func()()(x) -> same as (func())(x)
but:
func(int)(x) -> could be func(int)x {...}
Fixes #4109.
R=rsc, r, iant, ken, iant
CC=golang-dev
https://golang.org/cl/6584065
This commit is contained in:
parent
256daf2c85
commit
3188ffc931
|
|
@ -1,6 +1,6 @@
|
|||
<!--{
|
||||
"Title": "The Go Programming Language Specification",
|
||||
"Subtitle": "Version of September 28, 2012",
|
||||
"Subtitle": "Version of October 3, 2012",
|
||||
"Path": "/ref/spec"
|
||||
}-->
|
||||
|
||||
|
|
@ -3394,7 +3394,8 @@ Conversion = Type "(" Expression [ "," ] ")" .
|
|||
</pre>
|
||||
|
||||
<p>
|
||||
If the type starts with an operator it must be parenthesized:
|
||||
If the type starts with the operator <code>*</code> or <code><-</code>,
|
||||
or the keyword <code>func</code>, it must be parenthesized:
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
|
|
@ -3402,6 +3403,8 @@ If the type starts with an operator it must be parenthesized:
|
|||
(*Point)(p) // p is converted to (*Point)
|
||||
<-chan int(c) // same as <-(chan int(c))
|
||||
(<-chan int)(c) // c is converted to (<-chan int)
|
||||
func()(x) // function signature func() x
|
||||
(func())(x) // x is converted to (func())
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
|
|
@ -3488,6 +3491,12 @@ 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>
|
||||
|
|
|
|||
Loading…
Reference in New Issue