]> Cypherpunks repositories - gostls13.git/commitdiff
undo 35108 (disallow parens around type in struct literal).
authorRuss Cox <rsc@golang.org>
Wed, 30 Sep 2009 04:21:14 +0000 (21:21 -0700)
committerRuss Cox <rsc@golang.org>
Wed, 30 Sep 2009 04:21:14 +0000 (21:21 -0700)
allow parens around [...]int in struct literal.

R=ken
OCL=35112
CL=35130

src/cmd/gc/go.y
src/pkg/reflect/all_test.go
test/fixedbugs/bug207.go [deleted file]
test/parentype.go

index 572481309d27d5b5cd3c464cbd319a948ce403e4..bf46f6c1ccaba659542a0ff752c14512b49d332d 100644 (file)
@@ -70,7 +70,7 @@
 %type  <list>  interfacedcl_list vardcl vardcl_list structdcl structdcl_list
 %type  <list>  common_dcl constdcl constdcl1 constdcl_list typedcl_list
 
-%type  <node>  convtype dotdotdot littype
+%type  <node>  convtype dotdotdot
 %type  <node>  indcl interfacetype structtype ptrtype
 %type  <node>  chantype non_chan_type othertype non_fn_type fntype
 
@@ -862,7 +862,7 @@ pexpr:
                if($2 == LBODY)
                        loophack = 1;
        }
-|      littype '{' braced_keyval_list '}'
+|      pexpr '{' braced_keyval_list '}'
        {
                // composite expression
                $$ = nod(OCOMPLIT, N, $1);
@@ -870,20 +870,6 @@ pexpr:
        }
 |      fnliteral
 
-littype:
-       name
-|      pexpr '.' sym
-       {
-               if($1->op == OPACK) {
-                       Sym *s;
-                       s = restrictlookup($3->name, $1->sym->name);
-                       $1->used = 1;
-                       $$ = oldname(s);
-                       break;
-               }
-               $$ = nod(OXDOT, $1, newname($3));
-       }
-
 expr_or_type:
        expr
 |      non_expr_type   %prec PreferToRightParen
@@ -956,7 +942,6 @@ convtype:
        }
 |      structtype
 
-
 /*
  * to avoid parsing conflicts, type is split into
  *     channel types
@@ -1031,6 +1016,11 @@ othertype:
        {
                $$ = nod(OTARRAY, $2, $4);
        }
+|      '[' dotdotdot ']' ntype
+       {
+               // array literal of nelem
+               $$ = nod(OTARRAY, $2, $4);
+       }
 |      LCOMM LCHAN ntype
        {
                $$ = nod(OTCHAN, $3, N);
index 9fad3947aa6234ad8a9180d4099d4fd09b7d7927..17a526c6fc71bd3dc936e71a1e3ee9e342f20bda 100644 (file)
@@ -84,15 +84,15 @@ var valueTests = []pair {
        pair { (bool)(false), "true" },
        pair { (*int8)(nil), "*int8(0)" },
        pair { (**int8)(nil), "**int8(0)" },
-       pair { [5]int32{}, "[5]int32{0, 0, 0, 0, 0}" },
+       pair { ([5]int32){}, "[5]int32{0, 0, 0, 0, 0}" },
        pair { (**integer)(nil), "**reflect_test.integer(0)" },
        pair { (map[string]int32)(nil), "map[string] int32{<can't iterate on maps>}" },
        pair { (chan<-string)(nil), "chan<- string" },
-       pair { struct {c chan *int32; d float32}{}, "struct { c chan *int32; d float32 }{chan *int32, 0}" },
+       pair { (struct {c chan *int32; d float32}){}, "struct { c chan *int32; d float32 }{chan *int32, 0}" },
        pair { (func(a int8, b int32))(nil), "func(int8, int32)(0)" },
-       pair { struct {c func(chan *integer, *int8)}{}, "struct { c func(chan *reflect_test.integer, *int8) }{func(chan *reflect_test.integer, *int8)(0)}" },
-       pair { struct {a int8; b int32}{}, "struct { a int8; b int32 }{0, 0}" },
-       pair { struct {a int8; b int8; c int32}{}, "struct { a int8; b int8; c int32 }{0, 0, 0}" },
+       pair { (struct {c func(chan *integer, *int8)}){}, "struct { c func(chan *reflect_test.integer, *int8) }{func(chan *reflect_test.integer, *int8)(0)}" },
+       pair { (struct {a int8; b int32}){}, "struct { a int8; b int32 }{0, 0}" },
+       pair { (struct {a int8; b int8; c int32}){}, "struct { a int8; b int8; c int32 }{0, 0, 0}" },
 }
 
 func testType(t *testing.T, i int, typ Type, want string) {
diff --git a/test/fixedbugs/bug207.go b/test/fixedbugs/bug207.go
deleted file mode 100644 (file)
index de68cfe..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-// $G $D/$F.go && $L $F.$A && ./$A.out
-
-// 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
-
-var _ = []int{}
-var _ = ([]int){}      // ERROR "syntax"
-var _ = [...]int{}
-var _ = ([...]int){}   // ERROR "syntax"
index dd9c4891c91f88b522c9232b94c487e05be622a4..d5729f820d233225722ba99ba1aac24490e93c77 100644 (file)
@@ -10,6 +10,10 @@ func f(interface{})
 func g() {}
 func main() {
        f(map[string]string{"a":"b","c":"d"});
+       f([...]int{1,2,3});
+       f(([...]int){1,2,3});
+       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)));
 }