]> Cypherpunks repositories - gostls13.git/commitdiff
allow parens to disambiguate types.
authorRuss Cox <rsc@golang.org>
Wed, 18 Feb 2009 18:07:46 +0000 (10:07 -0800)
committerRuss Cox <rsc@golang.org>
Wed, 18 Feb 2009 18:07:46 +0000 (10:07 -0800)
examples:

chan <- (chan int)
chan (<- chan int)
(map[string]func())("a": main)

R=ken
OCL=25151
CL=25151

src/cmd/gc/go.y
test/parentype.go [new file with mode: 0644]

index d68576428206041e126d5ba32152a3fe5e77761f..320c9c6849f84af1140f9a79c0c2990ccbd53dbe 100644 (file)
@@ -1004,6 +1004,10 @@ convtype:
                $$->type = $5;
        }
 |      structtype
+|      '(' type ')'
+       {
+               $$ = $2;
+       }
 
 /*
  * to avoid parsing conflicts, type is split into
@@ -1031,6 +1035,10 @@ Btype:
 |      Bchantype
 |      Bfntype
 |      Bothertype
+|      '(' type ')'
+       {
+               $$ = $2;
+       }
 
 non_name_type:
        chantype
@@ -1052,6 +1060,10 @@ Bnon_chan_type:
        nametype
 |      Bfntype
 |      Bothertype
+|      '(' Btype ')'
+       {
+               $$ = $2;
+       }
 
 Anon_fn_type:
        Achantype
@@ -1062,7 +1074,6 @@ Bnon_fn_type:
 |      Bchantype
 |      Bothertype
 
-
 nametype:
        LATYPE
        {
diff --git a/test/parentype.go b/test/parentype.go
new file mode 100644 (file)
index 0000000..f163f55
--- /dev/null
@@ -0,0 +1,17 @@
+// $G $D/$F.go
+
+// Copyright 2009 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+func f(interface{})
+func g() {}
+func main() {
+       f(map[string]string("a":"b","c":"d"));
+       f((map[string]string)("a":"b","c":"d"));
+       f((map[string]func())("a":g,"c":g));
+       f(make(chan(<-chan int)));
+       f(make(chan<-(chan int)));
+}