]> Cypherpunks repositories - gostls13.git/commitdiff
go spec: conversion types starting with "func" must be parenthesized
authorRobert Griesemer <gri@golang.org>
Wed, 3 Oct 2012 20:46:37 +0000 (13:46 -0700)
committerRobert Griesemer <gri@golang.org>
Wed, 3 Oct 2012 20:46:37 +0000 (13:46 -0700)
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

doc/go_spec.html

index de35425b3b158cfcd7d85ff550ad68cdba070f8a..165e9bebf2423191897feead91b11cf6f181228b 100644 (file)
@@ -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>&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>