diff --git a/go/types/call.go b/go/types/call.go index 80127142..d8b0d5c3 100644 --- a/go/types/call.go +++ b/go/types/call.go @@ -350,9 +350,6 @@ func (check *checker) selector(x *operand, e *ast.SelectorExpr) { isVariadic: sig.isVariadic, } - // TODO(gri) move this into exprInternal's call of check.selector - // since that's the only place where we need to record a dependency - // (requires that operands know method objects) check.addDeclDep(m) } else { @@ -418,9 +415,6 @@ func (check *checker) selector(x *operand, e *ast.SelectorExpr) { sig.recv = nil x.typ = &sig - // TODO(gri) see comment above for addDeclDep - check.addDeclDep(obj) - default: unreachable() } diff --git a/go/types/check_test.go b/go/types/check_test.go index bc95a48e..4cd7af77 100644 --- a/go/types/check_test.go +++ b/go/types/check_test.go @@ -53,6 +53,7 @@ var tests = [][]string{ {"testdata/cycles3.src"}, {"testdata/cycles4.src"}, {"testdata/init0.src"}, + {"testdata/init1.src"}, {"testdata/decls0.src"}, {"testdata/decls1.src"}, {"testdata/decls2a.src", "testdata/decls2b.src"}, diff --git a/go/types/stdlib_test.go b/go/types/stdlib_test.go index d5caccea..020c82a2 100644 --- a/go/types/stdlib_test.go +++ b/go/types/stdlib_test.go @@ -125,6 +125,7 @@ func TestStdtest(t *testing.T) { func TestStdfixed(t *testing.T) { testTestDir(t, filepath.Join(runtime.GOROOT(), "test", "fixedbugs"), "bug248.go", "bug302.go", "bug369.go", // complex test instructions - ignore + "bug459.go", // incorrect test - see issue 6793 (pending spec clarification) "issue3924.go", // incorrect test - see issue 6671 "issue4847.go", // TODO(gri) initialization cycle error not found ) diff --git a/go/types/testdata/init0.src b/go/types/testdata/init0.src index 889c4b1c..ffaebaa5 100644 --- a/go/types/testdata/init0.src +++ b/go/types/testdata/init0.src @@ -68,12 +68,11 @@ func (T1) m() bool { _ = x11; return false } var x11 /* ERROR initialization cycle */ = T1.m(T1{}) -// cycles via method values +// no cycles via method values type T2 struct{} func (T2) m() bool { _ = x12; return false } var t1 T2 -var x12 /* ERROR initialization cycle */ = t1.m - +var x12 = t1.m diff --git a/go/types/testdata/init1.src b/go/types/testdata/init1.src new file mode 100644 index 00000000..b7379130 --- /dev/null +++ b/go/types/testdata/init1.src @@ -0,0 +1,73 @@ +// Copyright 2013 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. + +// initialization cycles + +package init1 + +// issue 6683 (marked as WorkingAsIntended) + +type T0 struct{} + +func (T0) m() int { return y0 } + +var x0 = T0{} + +var y0 = x0.m() // no cycle reported + +type T1 struct{} + +func (T1) m() int { return y1 } + +var x1 interface { + m() int +} = T1{} + +var y1 = x1.m() // no cycle reported + +// issue 6703 (modified) + +var x2 /* ERROR initialization cycle */ = T2.m + +var y2 = x2 + +type T2 struct{} + +func (T2) m() int { + _ = y2 + return 0 +} + +var x3 /* ERROR initialization cycle */ = T3.m(T3{}) // <<<< added (T3{}) + +var y3 = x3 + +type T3 struct{} + +func (T3) m() int { + _ = y3 + return 0 +} + +var x4 = T4{}.m // <<<< added {} + +var y4 = x4 + +type T4 struct{} + +func (T4) m() int { + _ = y4 + return 0 +} + +var x5 = T5{}.m() // <<<< added () + +var y5 = x5 + +type T5 struct{} + +func (T5) m() int { + _ = y5 + return 0 +} diff --git a/go/types/typexpr.go b/go/types/typexpr.go index d10b076a..20b86f9f 100644 --- a/go/types/typexpr.go +++ b/go/types/typexpr.go @@ -89,9 +89,6 @@ func (check *checker) ident(x *operand, e *ast.Ident, def *Named, cycleOk bool) case *Var: obj.used = true x.mode = variable - // TODO(gri) move this into exprInternal's call of check.ident - // since that's the only place where we need to record a dependency - // (requires that operands know variable objects) if typ != Typ[Invalid] { check.addDeclDep(obj) } @@ -99,7 +96,6 @@ func (check *checker) ident(x *operand, e *ast.Ident, def *Named, cycleOk bool) case *Func: obj.used = true x.mode = value - // TODO(gri) see comment above for addDeclDep if typ != Typ[Invalid] { check.addDeclDep(obj) }