mirror of
https://github.com/golang/go
synced 2024-11-11 17:21:38 -07:00
cmd/compile: use "init... cycle" instead of "init... loop" in error messages
For #55326. Change-Id: Ia3c1124305986dcd49ac769e700055b263cfbd59 Reviewed-on: https://go-review.googlesource.com/c/go/+/432615 Reviewed-by: Robert Findley <rfindley@google.com> Auto-Submit: Robert Griesemer <gri@google.com> Run-TryBot: Robert Griesemer <gri@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@google.com>
This commit is contained in:
parent
5d213a3dc7
commit
c58bfeeb04
@ -153,11 +153,7 @@ func findPath(objMap map[Object]*declInfo, from, to Object, seen map[Object]bool
|
|||||||
func (check *Checker) reportCycle(cycle []Object) {
|
func (check *Checker) reportCycle(cycle []Object) {
|
||||||
obj := cycle[0]
|
obj := cycle[0]
|
||||||
var err error_
|
var err error_
|
||||||
if check.conf.CompilerErrorMessages {
|
err.errorf(obj, "initialization cycle for %s", obj.Name())
|
||||||
err.errorf(obj, "initialization loop for %s", obj.Name())
|
|
||||||
} else {
|
|
||||||
err.errorf(obj, "initialization cycle for %s", obj.Name())
|
|
||||||
}
|
|
||||||
// subtle loop: print cycle[i] for i = 0, n-1, n-2, ... 1 for len(cycle) = n
|
// subtle loop: print cycle[i] for i = 0, n-1, n-2, ... 1 for len(cycle) = n
|
||||||
for i := len(cycle) - 1; i >= 0; i-- {
|
for i := len(cycle) - 1; i >= 0; i-- {
|
||||||
err.errorf(obj, "%s refers to", obj.Name())
|
err.errorf(obj, "%s refers to", obj.Name())
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
var (
|
var (
|
||||||
a, b = f() // ERROR "initialization loop|depends upon itself|depend upon each other"
|
a, b = f() // ERROR "initialization cycle|depends upon itself|depend upon each other"
|
||||||
c = b // GCCGO_ERROR "depends upon itself|depend upon each other"
|
c = b // GCCGO_ERROR "depends upon itself|depend upon each other"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
// check that initialization loop is diagnosed
|
// check that initialization cycle is diagnosed
|
||||||
// and that closure cannot be used to hide it.
|
// and that closure cannot be used to hide it.
|
||||||
// error message is not standard format, so no errchk above.
|
// error message is not standard format, so no errchk above.
|
||||||
|
|
||||||
@ -18,4 +18,4 @@ func f() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var m = map[string]F{"f": f} // ERROR "initialization loop|depends upon itself|initialization cycle"
|
var m = map[string]F{"f": f} // ERROR "initialization cycle|depends upon itself|initialization cycle"
|
||||||
|
@ -8,4 +8,4 @@ package p
|
|||||||
|
|
||||||
func f(i int) int { return i }
|
func f(i int) int { return i }
|
||||||
|
|
||||||
var i = func() int {a := f(i); return a}() // ERROR "initialization loop|depends upon itself"
|
var i = func() int {a := f(i); return a}() // ERROR "initialization cycle|depends upon itself"
|
||||||
|
@ -4,12 +4,12 @@
|
|||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
// Issue 3890: missing detection of init loop involving
|
// Issue 3890: missing detection of init cycle involving
|
||||||
// method calls in function bodies.
|
// method calls in function bodies.
|
||||||
|
|
||||||
package flag
|
package flag
|
||||||
|
|
||||||
var commandLine = NewFlagSet() // ERROR "loop|depends upon itself"
|
var commandLine = NewFlagSet() // ERROR "initialization cycle|depends upon itself"
|
||||||
|
|
||||||
type FlagSet struct {
|
type FlagSet struct {
|
||||||
}
|
}
|
||||||
|
@ -9,11 +9,11 @@
|
|||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
const a = a // ERROR "refers to itself|definition loop|initialization loop"
|
const a = a // ERROR "refers to itself|definition loop|initialization cycle"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
X = A
|
X = A
|
||||||
A = B // ERROR "refers to itself|definition loop|initialization loop"
|
A = B // ERROR "refers to itself|definition loop|initialization cycle"
|
||||||
B = D
|
B = D
|
||||||
C, D = 1, A
|
C, D = 1, A
|
||||||
)
|
)
|
||||||
|
@ -6,4 +6,4 @@
|
|||||||
|
|
||||||
package p
|
package p
|
||||||
|
|
||||||
var f = func() { f() } // ERROR "initialization loop|initialization expression for .*f.* depends upon itself"
|
var f = func() { f() } // ERROR "initialization cycle|initialization expression for .*f.* depends upon itself"
|
||||||
|
@ -8,4 +8,4 @@
|
|||||||
|
|
||||||
package p
|
package p
|
||||||
|
|
||||||
var a [len(a)]int // ERROR "\[len\(a\)\]int|initialization loop"
|
var a [len(a)]int // ERROR "\[len\(a\)\]int|initialization cycle"
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
// Issue 4847: initialization loop is not detected.
|
// Issue 4847: initialization cycle is not detected.
|
||||||
|
|
||||||
package p
|
package p
|
||||||
|
|
||||||
@ -19,6 +19,6 @@ func matchList(s *S) E { return matcher(matchAnyFn)(s) }
|
|||||||
|
|
||||||
var foo = matcher(matchList)
|
var foo = matcher(matchList)
|
||||||
|
|
||||||
var matchAny = matcher(matchList) // ERROR "initialization loop|depends upon itself"
|
var matchAny = matcher(matchList) // ERROR "initialization cycle|depends upon itself"
|
||||||
|
|
||||||
func matchAnyFn(s *S) (err E) { return matchAny(s) }
|
func matchAnyFn(s *S) (err E) { return matchAny(s) }
|
||||||
|
@ -10,4 +10,4 @@ import "unsafe"
|
|||||||
|
|
||||||
type S[T any] struct{}
|
type S[T any] struct{}
|
||||||
|
|
||||||
const c = unsafe.Sizeof(S[[c]byte]{}) // ERROR "initialization loop"
|
const c = unsafe.Sizeof(S[[c]byte]{}) // ERROR "initialization cycle"
|
||||||
|
@ -13,4 +13,4 @@ func fx() int {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
var x = fx // ERROR "initialization loop|depends upon itself"
|
var x = fx // ERROR "initialization cycle|depends upon itself"
|
||||||
|
@ -13,4 +13,4 @@ func fx() int {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
var x = fx() // ERROR "initialization loop|depends upon itself"
|
var x = fx() // ERROR "initialization cycle|depends upon itself"
|
||||||
|
@ -15,4 +15,4 @@ func (T) m() int {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
var x = T.m // ERROR "initialization loop|depends upon itself"
|
var x = T.m // ERROR "initialization cycle|depends upon itself"
|
||||||
|
@ -15,4 +15,4 @@ func (T) m() int {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
var x = T.m(0) // ERROR "initialization loop|depends upon itself"
|
var x = T.m(0) // ERROR "initialization cycle|depends upon itself"
|
||||||
|
@ -15,4 +15,4 @@ func (T) m() int {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
var x = T(0).m // ERROR "initialization loop|depends upon itself"
|
var x = T(0).m // ERROR "initialization cycle|depends upon itself"
|
||||||
|
@ -15,4 +15,4 @@ func (T) m() int {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
var x = T(0).m() // ERROR "initialization loop|depends upon itself"
|
var x = T(0).m() // ERROR "initialization cycle|depends upon itself"
|
||||||
|
@ -17,4 +17,4 @@ func (T) m() int {
|
|||||||
|
|
||||||
type E struct{ T }
|
type E struct{ T }
|
||||||
|
|
||||||
var x = E.m // ERROR "initialization loop|depends upon itself"
|
var x = E.m // ERROR "initialization cycle|depends upon itself"
|
||||||
|
@ -17,4 +17,4 @@ func (T) m() int {
|
|||||||
|
|
||||||
type E struct{ T }
|
type E struct{ T }
|
||||||
|
|
||||||
var x = E.m(E{0}) // ERROR "initialization loop|depends upon itself"
|
var x = E.m(E{0}) // ERROR "initialization cycle|depends upon itself"
|
||||||
|
@ -17,4 +17,4 @@ func (T) m() int {
|
|||||||
|
|
||||||
type E struct{ T }
|
type E struct{ T }
|
||||||
|
|
||||||
var x = E{}.m // ERROR "initialization loop|depends upon itself"
|
var x = E{}.m // ERROR "initialization cycle|depends upon itself"
|
||||||
|
@ -17,4 +17,4 @@ func (T) m() int {
|
|||||||
|
|
||||||
type E struct{ T }
|
type E struct{ T }
|
||||||
|
|
||||||
var x = E{}.m() // ERROR "initialization loop|depends upon itself"
|
var x = E{}.m() // ERROR "initialization cycle|depends upon itself"
|
||||||
|
@ -17,5 +17,5 @@ func (T) m() int {
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
t T
|
t T
|
||||||
x = t.m // ERROR "initialization loop|depends upon itself"
|
x = t.m // ERROR "initialization cycle|depends upon itself"
|
||||||
)
|
)
|
||||||
|
@ -17,5 +17,5 @@ func (T) m() int {
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
t T
|
t T
|
||||||
x = t.m() // ERROR "initialization loop|depends upon itself"
|
x = t.m() // ERROR "initialization cycle|depends upon itself"
|
||||||
)
|
)
|
||||||
|
@ -21,5 +21,5 @@ func f() T {
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
t T
|
t T
|
||||||
x = f().m // ERROR "initialization loop|depends upon itself"
|
x = f().m // ERROR "initialization cycle|depends upon itself"
|
||||||
)
|
)
|
||||||
|
@ -21,5 +21,5 @@ func f() T {
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
t T
|
t T
|
||||||
x = f().m() // ERROR "initialization loop|depends upon itself"
|
x = f().m() // ERROR "initialization cycle|depends upon itself"
|
||||||
)
|
)
|
||||||
|
@ -19,5 +19,5 @@ type E struct{ T }
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
e E
|
e E
|
||||||
x = e.m // ERROR "initialization loop|depends upon itself"
|
x = e.m // ERROR "initialization cycle|depends upon itself"
|
||||||
)
|
)
|
||||||
|
@ -19,5 +19,5 @@ type E struct{ T }
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
e E
|
e E
|
||||||
x = e.m() // ERROR "initialization loop|depends upon itself"
|
x = e.m() // ERROR "initialization cycle|depends upon itself"
|
||||||
)
|
)
|
||||||
|
@ -24,5 +24,5 @@ type E struct{ T }
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
e E
|
e E
|
||||||
x = g().m // ERROR "initialization loop|depends upon itself"
|
x = g().m // ERROR "initialization cycle|depends upon itself"
|
||||||
)
|
)
|
||||||
|
@ -24,5 +24,5 @@ type E struct{ T }
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
e E
|
e E
|
||||||
x = g().m() // ERROR "initialization loop|depends upon itself"
|
x = g().m() // ERROR "initialization cycle|depends upon itself"
|
||||||
)
|
)
|
||||||
|
@ -15,4 +15,4 @@ func (*T) pm() int {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
var x = (*T).pm // ERROR "initialization loop|depends upon itself"
|
var x = (*T).pm // ERROR "initialization cycle|depends upon itself"
|
||||||
|
@ -15,4 +15,4 @@ func (*T) pm() int {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
var x = (*T).pm(nil) // ERROR "initialization loop|depends upon itself"
|
var x = (*T).pm(nil) // ERROR "initialization cycle|depends upon itself"
|
||||||
|
@ -15,4 +15,4 @@ func (*T) pm() int {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
var x = (*T)(nil).pm // ERROR "initialization loop|depends upon itself"
|
var x = (*T)(nil).pm // ERROR "initialization cycle|depends upon itself"
|
||||||
|
@ -15,4 +15,4 @@ func (*T) pm() int {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
var x = (*T)(nil).pm() // ERROR "initialization loop|depends upon itself"
|
var x = (*T)(nil).pm() // ERROR "initialization cycle|depends upon itself"
|
||||||
|
@ -17,5 +17,5 @@ func (*T) pm() int {
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
p *T
|
p *T
|
||||||
x = p.pm // ERROR "initialization loop|depends upon itself"
|
x = p.pm // ERROR "initialization cycle|depends upon itself"
|
||||||
)
|
)
|
||||||
|
@ -17,5 +17,5 @@ func (*T) pm() int {
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
p *T
|
p *T
|
||||||
x = p.pm() // ERROR "initialization loop|depends upon itself"
|
x = p.pm() // ERROR "initialization cycle|depends upon itself"
|
||||||
)
|
)
|
||||||
|
@ -20,4 +20,4 @@ func pf() *T {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var x = pf().pm // ERROR "initialization loop|depends upon itself"
|
var x = pf().pm // ERROR "initialization cycle|depends upon itself"
|
||||||
|
@ -20,4 +20,4 @@ func pf() *T {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var x = pf().pm() // ERROR "initialization loop|depends upon itself"
|
var x = pf().pm() // ERROR "initialization cycle|depends upon itself"
|
||||||
|
@ -10,6 +10,6 @@ package main
|
|||||||
|
|
||||||
import "unsafe"
|
import "unsafe"
|
||||||
|
|
||||||
var x struct { // GC_ERROR "initialization loop for x"
|
var x struct { // GC_ERROR "initialization cycle for x"
|
||||||
a [unsafe.Sizeof(x.a)]int // GCCGO_ERROR "array bound|typechecking loop|invalid expression"
|
a [unsafe.Sizeof(x.a)]int // GCCGO_ERROR "array bound|typechecking loop|invalid expression"
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,6 @@
|
|||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
var y struct { // GC_ERROR "initialization loop for y"
|
var y struct { // GC_ERROR "initialization cycle for y"
|
||||||
d [len(y.d)]int // GCCGO_ERROR "array bound|typechecking loop|invalid array"
|
d [len(y.d)]int // GCCGO_ERROR "array bound|typechecking loop|invalid array"
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,6 @@
|
|||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
var z struct { // GC_ERROR "initialization loop for z"
|
var z struct { // GC_ERROR "initialization cycle for z"
|
||||||
e [cap(z.e)]int // GCCGO_ERROR "array bound|typechecking loop|invalid array"
|
e [cap(z.e)]int // GCCGO_ERROR "array bound|typechecking loop|invalid array"
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,6 @@ package main
|
|||||||
|
|
||||||
import "unsafe"
|
import "unsafe"
|
||||||
|
|
||||||
var x struct { // GC_ERROR "initialization loop for x"
|
var x struct { // GC_ERROR "initialization cycle for x"
|
||||||
b [unsafe.Offsetof(x.b)]int // GCCGO_ERROR "array bound|typechecking loop|invalid array"
|
b [unsafe.Offsetof(x.b)]int // GCCGO_ERROR "array bound|typechecking loop|invalid array"
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,6 @@ package main
|
|||||||
|
|
||||||
import "unsafe"
|
import "unsafe"
|
||||||
|
|
||||||
var x struct { // GC_ERROR "initialization loop for x"
|
var x struct { // GC_ERROR "initialization cycle for x"
|
||||||
c [unsafe.Alignof(x.c)]int // GCCGO_ERROR "array bound|typechecking loop|invalid array"
|
c [unsafe.Alignof(x.c)]int // GCCGO_ERROR "array bound|typechecking loop|invalid array"
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ package p
|
|||||||
// and runs in a fraction of a second without it.
|
// and runs in a fraction of a second without it.
|
||||||
// 10 seconds (-t 10 above) should be plenty if the code is working.
|
// 10 seconds (-t 10 above) should be plenty if the code is working.
|
||||||
|
|
||||||
var x = f() + z() // ERROR "initialization loop"
|
var x = f() + z() // ERROR "initialization cycle"
|
||||||
|
|
||||||
func f() int { return a1() + a2() + a3() + a4() + a5() + a6() + a7() }
|
func f() int { return a1() + a2() + a3() + a4() + a5() + a6() + a7() }
|
||||||
func z() int { return x }
|
func z() int { return x }
|
||||||
|
@ -9,6 +9,6 @@
|
|||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
const A = 1 + B // ERROR "constant definition loop\n.*A uses B\n.*B uses C\n.*C uses A|initialization loop"
|
const A = 1 + B // ERROR "constant definition loop\n.*A uses B\n.*B uses C\n.*C uses A|initialization cycle"
|
||||||
const B = C - 1 // ERROR "constant definition loop\n.*B uses C\n.*C uses B|initialization loop"
|
const B = C - 1 // ERROR "constant definition loop\n.*B uses C\n.*C uses B|initialization cycle"
|
||||||
const C = A + B + 1
|
const C = A + B + 1
|
||||||
|
Loading…
Reference in New Issue
Block a user