mirror of
https://github.com/golang/go
synced 2024-11-19 04:24: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:
parent
d84d338a42
commit
b33df7e76a
@ -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 {
|
if sig, ok := check.typ(e.Type, nil, false).(*Signature); ok {
|
||||||
x.mode = value
|
x.mode = value
|
||||||
x.typ = sig
|
x.typ = sig
|
||||||
// TODO(gri) provide correct *declInfo here
|
// Anonymous functions are considered part of the
|
||||||
check.later(nil, nil, sig, e.Body)
|
// init expression/func declaration which contains
|
||||||
|
// them: use the current package-level declaration
|
||||||
|
// info.
|
||||||
|
check.later(nil, check.decl, sig, e.Body)
|
||||||
} else {
|
} else {
|
||||||
check.invalidAST(e.Pos(), "invalid function literal %s", e)
|
check.invalidAST(e.Pos(), "invalid function literal %s", e)
|
||||||
goto Error
|
goto Error
|
||||||
|
@ -124,7 +124,7 @@ func TestStdtest(t *testing.T) {
|
|||||||
|
|
||||||
func TestStdfixed(t *testing.T) {
|
func TestStdfixed(t *testing.T) {
|
||||||
testTestDir(t, filepath.Join(runtime.GOROOT(), "test", "fixedbugs"),
|
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
|
"bug248.go", "bug302.go", "bug369.go", // complex test instructions - ignore
|
||||||
"issue3924.go", // incorrect test - see issue 6671
|
"issue3924.go", // incorrect test - see issue 6671
|
||||||
"issue4847.go", // TODO(gri) initialization cycle error not found
|
"issue4847.go", // TODO(gri) initialization cycle error not found
|
||||||
|
12
go/types/testdata/init0.src
vendored
12
go/types/testdata/init0.src
vendored
@ -44,3 +44,15 @@ var x6, x7 /* ERROR initialization cycle */ = f2()
|
|||||||
var x8 = x7
|
var x8 = x7
|
||||||
func f2() (int, int) { return f3() + f3(), 0 }
|
func f2() (int, int) { return f3() + f3(), 0 }
|
||||||
func f3() int { return x8 }
|
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
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user