]> Cypherpunks repositories - gostls13.git/commitdiff
put toplevel & check back and add test
authorRuss Cox <rsc@golang.org>
Thu, 16 Oct 2008 21:02:20 +0000 (14:02 -0700)
committerRuss Cox <rsc@golang.org>
Thu, 16 Oct 2008 21:02:20 +0000 (14:02 -0700)
R=ken
OCL=17307
CL=17307

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

index 656bc64867991d364c4baa68f97d1e28ea6b8f32..3e69c305e79bb9a743f23ce4bf6f109a4a1b9a3b 100644 (file)
@@ -754,6 +754,8 @@ uexpr:
        }
 |      '&' uexpr
        {
+               if($2->op == OCONV && !func)
+                       yyerror("& of composite literal at top level");
                $$ = nod(OADDR, $2, N);
        }
 |      '+' uexpr
@@ -1179,11 +1181,13 @@ xfndcl:
        {
                maxarg = 0;
                stksize = 0;
+               func++;
        } fndcl fnbody
        {
                $$ = $3;
                $$->nbody = $4;
                funcbody($$);
+               func--;
        }
 
 fndcl:
diff --git a/test/addr.go b/test/addr.go
new file mode 100644 (file)
index 0000000..c803ee7
--- /dev/null
@@ -0,0 +1,9 @@
+// errchk $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
+
+var a = &[]int{1,2};   // ERROR "composite"