1
0
mirror of https://github.com/golang/go synced 2024-11-19 01:54:39 -07:00

go.tools/go/types: track init cycles through closures

R=adonovan
CC=golang-dev
https://golang.org/cl/21790044
This commit is contained in:
Robert Griesemer 2013-11-05 10:51:13 -08:00
parent d84d338a42
commit b33df7e76a
3 changed files with 18 additions and 3 deletions

View File

@ -969,8 +969,11 @@ func (check *checker) exprInternal(x *operand, e ast.Expr, hint Type) exprKind {
if sig, ok := check.typ(e.Type, nil, false).(*Signature); ok {
x.mode = value
x.typ = sig
// TODO(gri) provide correct *declInfo here
check.later(nil, nil, sig, e.Body)
// Anonymous functions are considered part of the
// init expression/func declaration which contains
// them: use the current package-level declaration
// info.
check.later(nil, check.decl, sig, e.Body)
} else {
check.invalidAST(e.Pos(), "invalid function literal %s", e)
goto Error

View File

@ -124,7 +124,7 @@ func TestStdtest(t *testing.T) {
func TestStdfixed(t *testing.T) {
testTestDir(t, filepath.Join(runtime.GOROOT(), "test", "fixedbugs"),
"bug223.go", "bug413.go", "bug459.go", // TODO(gri) complete initialization checks
"bug459.go", // TODO(gri) complete initialization checks
"bug248.go", "bug302.go", "bug369.go", // complex test instructions - ignore
"issue3924.go", // incorrect test - see issue 6671
"issue4847.go", // TODO(gri) initialization cycle error not found

View File

@ -44,3 +44,15 @@ var x6, x7 /* ERROR initialization cycle */ = f2()
var x8 = x7
func f2() (int, int) { return f3() + f3(), 0 }
func f3() int { return x8 }
// cycles via closures
var x9 /* ERROR initialization cycle */ = func() int { return x9 }()
var x10 /* ERROR initialization cycle */ = f4()
func f4() int {
_ = func() {
_ = x10
}
return 0
}