Commit 3188ffc9 authored by Robert Griesemer's avatar Robert Griesemer

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
parent 256daf2c
<!--{
"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>&lt;-</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)
&lt;-chan int(c) // same as &lt;-(chan int(c))
(&lt;-chan int)(c) // c is converted to (&lt;-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>
......
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