From 493a9d2f42a04dfcf7fd807ede4603429bf91d28 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Thu, 16 Oct 2008 14:02:20 -0700 Subject: [PATCH] put toplevel & check back and add test R=ken OCL=17307 CL=17307 --- src/cmd/gc/go.y | 4 ++++ test/addr.go | 9 +++++++++ 2 files changed, 13 insertions(+) create mode 100644 test/addr.go diff --git a/src/cmd/gc/go.y b/src/cmd/gc/go.y index 656bc64867..3e69c305e7 100644 --- a/src/cmd/gc/go.y +++ b/src/cmd/gc/go.y @@ -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 index 0000000000..c803ee7c25 --- /dev/null +++ b/test/addr.go @@ -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" -- 2.50.0