1
0
mirror of https://github.com/golang/go synced 2024-11-21 22:04:39 -07:00

gc: diagnose init loop involving func

Fixes #2295.

R=ken2
CC=golang-dev
https://golang.org/cl/5655057
This commit is contained in:
Russ Cox 2012-02-10 23:10:45 -05:00
parent 7ae1fe420e
commit 896f0c61c8
2 changed files with 13 additions and 2 deletions

View File

@ -65,7 +65,7 @@ init1(Node *n, NodeList **out)
if(nerrors > 0)
errorexit();
print("initialization loop:\n");
print("%L: initialization loop:\n", n->lineno);
for(l=initlist;; l=l->next) {
if(l->next == nil)
break;
@ -106,7 +106,7 @@ init1(Node *n, NodeList **out)
break;
*/
if(1) {
init1(n->defn->right, out);
init2(n->defn->right, out);
if(debug['j'])
print("%S\n", n->sym);
if(!staticinit(n, out)) {

11
test/fixedbugs/bug413.go Normal file
View File

@ -0,0 +1,11 @@
// errchk $G $D/$F.go
// Copyright 2012 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 p
func f(i int) int { return i }
var i = func() int {a := f(i); return a}() // ERROR "initialization loop"