1
0
mirror of https://github.com/golang/go synced 2024-11-25 22:07:58 -07:00

disallow parens around type in struct literal syntax,

per discussion with gri.

R=ken
OCL=35108
CL=35108
This commit is contained in:
Russ Cox 2009-09-29 16:05:44 -07:00
parent 8f8b735295
commit 9c3c140984
4 changed files with 34 additions and 9 deletions

View File

@ -70,7 +70,7 @@
%type <list> interfacedcl_list vardcl vardcl_list structdcl structdcl_list %type <list> interfacedcl_list vardcl vardcl_list structdcl structdcl_list
%type <list> common_dcl constdcl constdcl1 constdcl_list typedcl_list %type <list> common_dcl constdcl constdcl1 constdcl_list typedcl_list
%type <node> convtype dotdotdot %type <node> convtype dotdotdot littype
%type <node> indcl interfacetype structtype ptrtype %type <node> indcl interfacetype structtype ptrtype
%type <node> chantype non_chan_type othertype non_fn_type fntype %type <node> chantype non_chan_type othertype non_fn_type fntype
@ -862,7 +862,7 @@ pexpr:
if($2 == LBODY) if($2 == LBODY)
loophack = 1; loophack = 1;
} }
| pexpr '{' braced_keyval_list '}' | littype '{' braced_keyval_list '}'
{ {
// composite expression // composite expression
$$ = nod(OCOMPLIT, N, $1); $$ = nod(OCOMPLIT, N, $1);
@ -870,6 +870,20 @@ pexpr:
} }
| fnliteral | 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_or_type:
expr expr
| non_expr_type %prec PreferToRightParen | non_expr_type %prec PreferToRightParen
@ -942,6 +956,7 @@ convtype:
} }
| structtype | structtype
/* /*
* to avoid parsing conflicts, type is split into * to avoid parsing conflicts, type is split into
* channel types * channel types

View File

@ -84,15 +84,15 @@ var valueTests = []pair {
pair { (bool)(false), "true" }, pair { (bool)(false), "true" },
pair { (*int8)(nil), "*int8(0)" }, pair { (*int8)(nil), "*int8(0)" },
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 { (**integer)(nil), "**reflect_test.integer(0)" },
pair { (map[string]int32)(nil), "map[string] int32{<can't iterate on maps>}" }, pair { (map[string]int32)(nil), "map[string] int32{<can't iterate on maps>}" },
pair { (chan<-string)(nil), "chan<- string" }, 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 { (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 {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 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 {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) { func testType(t *testing.T, i int, typ Type, want string) {

12
test/fixedbugs/bug207.go Normal file
View File

@ -0,0 +1,12 @@
// $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"

View File

@ -10,8 +10,6 @@ func f(interface{})
func g() {} func g() {}
func main() { func main() {
f(map[string]string{"a":"b","c":"d"}); 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)));
f(make(chan<-(chan int))); f(make(chan<-(chan int)));
} }