mirror of
https://github.com/golang/go
synced 2024-11-22 01:44:40 -07:00
gc: top-level closure bug
Fixes #2055. R=ken2 CC=golang-dev https://golang.org/cl/4816059
This commit is contained in:
parent
f91eb3c2f9
commit
890bdc5339
@ -84,6 +84,11 @@ typecheckclosure(Node *func, int top)
|
|||||||
oldfn = curfn;
|
oldfn = curfn;
|
||||||
typecheck(&func->ntype, Etype);
|
typecheck(&func->ntype, Etype);
|
||||||
func->type = func->ntype->type;
|
func->type = func->ntype->type;
|
||||||
|
if(curfn == nil) {
|
||||||
|
xtop = list(xtop, func);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if(func->type != T) {
|
if(func->type != T) {
|
||||||
curfn = func;
|
curfn = func;
|
||||||
typechecklist(func->nbody, Etop);
|
typechecklist(func->nbody, Etop);
|
||||||
|
@ -255,7 +255,7 @@ main(int argc, char *argv[])
|
|||||||
resumecheckwidth();
|
resumecheckwidth();
|
||||||
|
|
||||||
for(l=xtop; l; l=l->next)
|
for(l=xtop; l; l=l->next)
|
||||||
if(l->n->op == ODCLFUNC) {
|
if(l->n->op == ODCLFUNC || l->n->op == OCLOSURE) {
|
||||||
curfn = l->n;
|
curfn = l->n;
|
||||||
saveerrors();
|
saveerrors();
|
||||||
typechecklist(l->n->nbody, Etop);
|
typechecklist(l->n->nbody, Etop);
|
||||||
@ -274,9 +274,10 @@ main(int argc, char *argv[])
|
|||||||
while(closures) {
|
while(closures) {
|
||||||
l = closures;
|
l = closures;
|
||||||
closures = nil;
|
closures = nil;
|
||||||
for(; l; l=l->next)
|
for(; l; l=l->next) {
|
||||||
funccompile(l->n, 1);
|
funccompile(l->n, 1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for(l=externdcl; l; l=l->next)
|
for(l=externdcl; l; l=l->next)
|
||||||
if(l->n->op == ONAME)
|
if(l->n->op == ONAME)
|
||||||
|
18
test/fixedbugs/bug355.go
Normal file
18
test/fixedbugs/bug355.go
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
// $G $D/$F.go && $L $F.$A && ./$A.out
|
||||||
|
|
||||||
|
// Copyright 2011 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 f = func() int {
|
||||||
|
type S int
|
||||||
|
return 42
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
if f() != 42 {
|
||||||
|
panic("BUG: bug355")
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user